mybatis插值,数据提交事务回滚数据库值为空
mybatis插值,数据提交事务回滚数据库值为空
通过sql日志查看sql为:INSERT INTO `quanxian`.`user` ( phone, email, password, times, name, age, address, sex, hobby, work ) VALUES (phone, email, password, times, name, age, address, sex, hobby, work );
1.0
初步怀疑是入参类型不对,于是检查类型:<insert id="addUser" parameterType="com.ry.project.vo.User">
入参类型没问题
2.0
继续查看Mapper接口:int addUser(User user);
接口没问题
3.0
于是控制台打印入参看看是否为空:{"address":"长江以北暂不繁华之处","age":20,"email":"","hobby":"电鱼","id":91,"name":"汤姆猫","password":"abc53814efg","phone":"18856519837","sex":"女","times":"2019-11-05 13:51:17","work":"电工"}
入参也没问题
4.0
回头继续检查mapper.xml文件
<trim prefixOverrides=","> <if test="phone !=null">, `phone`=#{phone} </if> <if test="email !=null">, `email`=#{email} </if> <if test="password!=null">, `password`=#{password}</if> <if test="times!=null">,`times`=#{times} </if> <if test="name!=null">,`name`=#{name} </if> <if test="age!=null">,`age`=#{age} </if> <if test="address!=null">,`address`=#{address} </if> <if test="sex!=null">,`sex`=#{sex}</if> <if test="hobby!=null">,`hobby`=#{hobby} </if> <if test="work!=null">, `work`=#{work}</if></trim>发现入参为实体时添加插值没有指定jdbc类型,于是添加类型<if test="phone != null">#{phone,jdbcType=VARCHAR},</if><if test="email != null">#{email,jdbcType=VARCHAR},</if><if test="password != null">#{password,jdbcType=VARCHAR},</if><if test="times != null">#{times,jdbcType=VARCHAR},</if><if test="name != null">#{name,jdbcType=VARCHAR},</if><if test="age != null">#{age,jdbcType=INTEGER},</if><if test="address != null">#{address,jdbcType=VARCHAR},</if><if test="sex != null">#{sex,jdbcType=VARCHAR},</if><if test="hobby != null">#{hobby,jdbcType=VARCHAR},</if><if test="work != null">#{work,jdbcType=VARCHAR},</if>至此问解决
相关推荐
debugjoker 2020-04-10
snowphy 2020-05-09
予衡飞翔 2020-01-05
csuzxm000 2020-01-09
fengdos 2020-01-04
牧场SZShepherd 2020-01-03
boredbird 2020-01-03
applex 2020-01-02
vivenwan 2019-12-17
achiverhai 2019-12-07
zhaojp0 2019-11-17
happyfling 2017-07-23
大伟爱自由 2018-05-11
industry0 2019-01-23
hehezhou 2018-05-11
lhhhoo 2013-07-17
fairystepwgl 2013-10-14
RogerCoderLife 2019-07-01