mysql 动态sql语法

mapper.xml  关键词

?xml [version="1.0" encoding="utf-8"]
!DOCTYPE[mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"]

mapper [namespace]>+

resultMap[id type]>+


    id[column jdbcType property]+
    result[column jdbcType property]+


resultMap[id type extends]>+


id[column jdbcType property]+
result[column jdbcType property]+


sql[id]


delete[id="" parameterType=""]


update[id="" parameterType=""]set>
if[test]

insert[id="" parameterType=""]>


trim[prefix="(" suffix=")" suffixOverrides=","]>
if[test]


select[id  parameterType resultType]>


include [refid]+


if[test]>+
bind[name  value]


choose-when[test]+


foreach[collection item index  open separator close]

动态sql-if

<if test="title != null">
    AND title like #{title}
</if>
<if test="author != null and author.name != null">
    AND author_name like #{author.name}
</if>

动态sql-choose-when-otherwise

<choose>
    <when test="title != null">
      AND title like #{title}
    </when>
    <when test="author != null and author.name != null">
      AND author_name like #{author.name}
    </when>
    <otherwise>
      AND featured = 1
    </otherwise>
</choose>

动态sql-foreach

<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
    #{item}
</foreach>

动态sql-bind

<bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
SELECT * FROM BLOG WHERE title LIKE #{pattern}


 


https://www.cnblogs.com/-crazysnail/p/3924792.html#choose

发布了231 篇原创文章 · 获赞 3 · 访问量 7992

猜你喜欢

转载自blog.csdn.net/qq_32265719/article/details/103891347
今日推荐