首页 > 其他 > 详细

MyBatis动态插入的实现

时间:2020-04-05 11:30:31      阅读:70      评论:0      收藏:0      [点我收藏+]

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>

技术分享图片

MyBatis动态插入的实现

原文:https://www.cnblogs.com/charlottepl/p/12636134.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!