sql片段
来源:互联网 发布:大乐透真假揭秘知乎 编辑:程序博客网 时间:2024/06/05 20:00
<!-- 将用户查询条件定义为sql片段 建议对单表的查询条件单独抽取sql片段,提高公用性 注意:不要将where标签放在sql片段,where标签可能有其他条件 --> <sql id="query_user_where"> <if test="username!=null and username!=''"> and username like '%${username}%' </if> <if test="sex!=null and sex!=''"> and sex = #{sex} </if> <!-- 还有很的查询条件 --> </sql> <!-- 自定义查询条件查询用户的信息 --> <select id="findUserList" parameterType="userQueryVo" resultType="user"> select id,username,birthday from user <!-- where标签相当 于where关键字,可以自动去除第一个and --> <where> <!-- 引用sql片段,如果sql片段和引用处不在同一个mapper必须前边加namespace --> <include refid="query_user_where"></include> <!-- 下边还有很其它的条件 --> <!-- <include refid="其它的sql片段"></include> --> </where> </select> <!-- 输出简单类型 功能:自定义查询条件,返回查询记录个数,通常用于实现 查询分页 --> <select id="findUserCount" parameterType="userQueryVo" resultType="int"> select count(*) from user <!-- where标签相当 于where关键字,可以自动去除第一个and --> <where> <!-- 引用sql片段,如果sql片段和引用处不在同一个mapper必须前边加namespace --> <include refid="query_user_where"></include> <!-- 下边还有很其它的条件 --> <!-- <include refid="其它的sql片段"></include> --> </where> </select></mapper>
阅读全文
0 0
- sql片段
- SQL 代码片段
- SQL注入片段
- JavaEE_Mybatis_SpringMVC_Mybatis_lesson9_引用SQL片段
- Sql查询片段
- 动态SQL片段
- MyBatis中的Sql片段使用
- 【MyBatis学习09】SQL片段
- 30、SQL片段的解析
- [mybatis]动态SQL与SQL片段
- Mybatis动态sql和sql片段
- Mybatis_01_理解动态sql及sql片段
- 片段
- 片段
- 片段
- 片段
- iBATIS如何复用SQL片段(翻译)
- 时间比较的SQL语句片段
- Java垃圾回收(整理)
- Tomcat优化,JNDI,连接池,数据源
- 排序
- 浮点数的二分写法以及判断大小
- Py_ClassAndMod
- sql片段
- gcc 5.3 install
- x&(x-1)
- idea project中导入其他文件夹下的模块,可能出现java.io.FileNotFoundException: XXX.xml
- 热风焊盘和隔离焊盘关系
- Py_logging
- 第三周训练总结(二)
- 欢迎使用CSDN-markdown编辑器
- Linux