1.场景分析
在实际的项目需求中,有很多字段数值为空,这时需要我们采取有效的方式避免空值插入数据库,今天主要讲解一下动态sql标签trim的用法
2.实现步骤
实际需求:插入一条用户信息,空值不允许插入
1>取消指定的后缀
①mapper中的sql
<insert id="insertUserInfoByTrim" parameterType="com.cckj.bean.UserInfo">
INSERT into userinfo
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="username !=null and username != ''">
username,
</if>
<if test="sex !=null and sex != ''">
sex,
</if>
<if test="age !=null">
age,
</if>
<if test="phone !=null and phone != ''">
phone,
</if>
<if test="address !=null