mybatis动态sql
2017-04-27 22:48
211 查看
在mybatis中,它提供了一些动态sql标签,可以让程序员更快的进行mybatis的开发,这些动态sql可以通过sql的可重用性。
提供了几种标签;
if标签/where标签:
sql片段的使用:
and id in
#{id}
提供了几种标签;
if标签/where标签:
<select id="findUserList" parameterType="com.sgn.mybatis.po.UserQueryVo" resultType="user"> select * from user <!-- <where>标签:默认去掉后面第一and,如果没有参数则把自己干掉 --> <where> <!-- if 标签:可以对输入的参数进行判断 test:指定判断表达式--> <if test="user != null"> <if test="user.username != null and user.username != ''"> and username like '%${user.username}%' </if> <if test="user.sex !=null and user.sex!=''"> and sex = #{user.sex} </if> </if> </where> </select>
sql片段的使用:
<sql id="query"> <!-- <where>标签:默认去掉后面第一and,如果没有参数则把自己干掉 --> <where> <!-- if 标签:可以对输入的参数进行判断 test:指定判断表达式--> <if test="user != null"> <if test="user.username != null and user.username != ''"> and username like '%${user.username}%' </if> <if test="user.sex !=null and user.sex!=''"> and sex = #{user.sex} </if> </if> </where> </sql> <select id="findUserList" parameterType="com.sgn.mybatis.po.UserQueryVo" resultType="user"> select * from user <include refid="query"></include> </select>
and id in
#{id}
相关文章推荐
- 深入浅出Mybatis系列(九)---强大的动态SQL
- mybatis(六) 输入映射 输出映射 resultType:resultMap 动态sql sql片段 if判断 foreach
- mybatis 动态sql
- MyBatis学习 之 三、动态SQL语句
- MyBatis 动态SQL语句
- MyBatis学习总结(六)——动态SQL
- Mybatis 动态sql
- MyBatis构建sql时动态传入表名以及字段名
- 关于mybatis 动态 sql 的一些陷阱:防止批量update,delete,select...
- MyBatis的动态SQL详解
- 8~mybatis的动态sql
- MyBatis的动态SQL详解
- MyBatis的动态SQL详解
- MyBatis——动态SQL
- Mybatis 动态sql
- mybatis-使用choose动态拼接sql
- MyBatis的动态SQL操作--插入
- MyBatis(五) 动态SQL
- MyBatis的构建,动态sql的语句
- mybatis动态sql中的trim标签的使用