码迷,mamicode.com
首页 > 数据库 > 详细

mybatis插值,数据提交事务回滚数据库值为空

时间:2020-06-25 13:58:55      阅读:49      评论:0      收藏:0      [点我收藏+]

标签:phone   sql   事务   提交   ESS   查看   解决   ati   XML   

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":"727843252@qq.com","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>

至此问解决

 

mybatis插值,数据提交事务回滚数据库值为空

标签:phone   sql   事务   提交   ESS   查看   解决   ati   XML   

原文地址:https://www.cnblogs.com/wangbiaohistory/p/13191559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!