当前位置:Gxlcms > 数据库问题 > mybatis插值,数据提交事务回滚数据库值为空

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

时间:2021-07-01 10:21:17 帮助过:7人阅读

入参类型没问题

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   

人气教程排行