通用Mapper中insert和insertSelective方法
通用Mapper中insert和insertSelective方法区别在于前者会对所有字段进行添加,而后者只对Selective的字段进行插入,代码层会有如下判断<insert id="insert" parameterType="com.ego.pojo.TbContentCategory" >insert into tb_content_category (id,...
·
通用Mapper中insert和insertSelective方法
区别在于前者会对所有字段进行添加,而后者只对Selective的字段进行插入,代码层会有如下判断
[ ps:在使用insertSelective方法插入时,为防止主键被插入空字符串可主动将其设置为null ]
<insert id="insert" parameterType="com.ego.pojo.TbContentCategory" >
insert into tb_content_category (id, parent_id, name,
status, sort_order, is_parent,
created, updated)
values (#{id,jdbcType=BIGINT}, #{parentId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{sortOrder,jdbcType=INTEGER}, #{isParent,jdbcType=BIT},
#{created,jdbcType=TIMESTAMP}, #{updated,jdbcType=TIMESTAMP})
<insert id="insertSelective" parameterType="com.ego.pojo.TbContentCategory" >
insert into tb_content_category
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="parentId != null" >
parent_id,
</if>
<if test="name != null" >
name,
</if>
<if test="status != null" >
status,
</if>
<if test="sortOrder != null" >
sort_order,
</if>
<if test="isParent != null" >
is_parent,
</if>
<if test="created != null" >
created,
</if>
<if test="updated != null" >
updated,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="parentId != null" >
#{parentId,jdbcType=BIGINT},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
<if test="sortOrder != null" >
#{sortOrder,jdbcType=INTEGER},
</if>
<if test="isParent != null" >
#{isParent,jdbcType=BIT},
</if>
<if test="created != null" >
#{created,jdbcType=TIMESTAMP},
</if>
<if test="updated != null" >
#{updated,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
更多推荐
已为社区贡献1条内容
所有评论(0)