mybatis通过定义前缀后缀和分割字符来拼接sql语句,实现动态插入的功能
<insert id="addNewsTypeByNewsId">
insert into news_newstype
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="newsId != null">
newsid,
</if>
<if test="newsTypeId != null and newsTypeId !=0">
newstypeid,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="newsId != null">
#{newsId},
</if>
<if test="newsTypeId != null and newsTypeId !=0">
#{newsTypeId},
</if>
</trim>
</insert>
原文地址:https://www.cnblogs.com/charlottepl/p/12636134.html
时间: 2024-10-11 16:24:34