mapper文件中返回主鍵:java
<insert id="insert" parameterType="com.za.cls.model.CompanyLeaseInfo" > <selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" > SELECT LAST_INSERT_ID() </selectKey> insert into company_lease_info (name, code, business_licence, oper_name, oper_phone, card_no, province_code, province_name, city_code, city_name, area_code, area_name, addr_detail, founded_time, contact_realname, contact_phone, contact_email, manager_id, open_account_status, status, create_time, modify_time) values (#{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{businessLicence,jdbcType=VARCHAR}, #{operName,jdbcType=VARCHAR}, #{operPhone,jdbcType=VARCHAR}, #{cardNo,jdbcType=VARCHAR}, #{provinceCode,jdbcType=VARCHAR}, #{provinceName,jdbcType=VARCHAR}, #{cityCode,jdbcType=VARCHAR}, #{cityName,jdbcType=VARCHAR}, #{areaCode,jdbcType=VARCHAR}, #{areaName,jdbcType=VARCHAR}, #{addrDetail,jdbcType=VARCHAR}, #{foundedTime,jdbcType=VARCHAR}, #{contactRealname,jdbcType=VARCHAR}, #{contactPhone,jdbcType=VARCHAR}, #{contactEmail,jdbcType=VARCHAR}, #{managerId,jdbcType=INTEGER}, #{openAccountStatus,jdbcType=BIT}, #{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP}) </insert>
在service層,調用這個方法後,根據getId方法能夠獲取主鍵。但在web層,controller的方法裏,卻獲取的是null。web
緣由:web層和service層是經過dubbo調用的,其對象不是同一個,故獲取不到主鍵。app
解決方法:在service層返回主鍵,web層直接獲取主鍵,而不是經過對象的getId方法獲取。code