1.抽取之前的UserMapper.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="com.hao.mapper.UserMapper">
<select id="findByCondition" parameterType="user" resultType="user">
select * from user
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>
<select id="findByIds" parameterType="list" resultType="user">
select * from user
<where>
<foreach collection="list" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
</mapper>

2.抽取之后的UserMapper.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="com.hao.mapper.UserMapper">
<!-- sql语句的抽取-->
<sql id="selectUser">select * from user</sql>
<select id="findByCondition" parameterType="user" resultType="user">
<include refid="selectUser"></include>
<where>
<if test="id!=0">
and id=#{id}
</if>
<if test="username!=null">
and username=#{username}
</if>
<if test="password!=null">
and password=#{password}
</if>
</where>
</select>
<select id="findByIds" parameterType="list" resultType="user">
<include refid="selectUser"></include>
<where>
<foreach collection="list" open="id in(" close=")" item="id" separator=",">
#{id}
</foreach>
</where>
</select>
</mapper>

refid:引用

最新文章

  1. list&lt;T&gt; 的使用方法。
  2. 关于C#消息调度(作业日志)
  3. MAVEN解决Cannot change version of project facet Dynamic web module to 2.5
  4. (HBase) Error: JAVA_HOME is not set and Java could not be found
  5. 引擎设计跟踪(九.14.2c) 最近一些小的更新
  6. 【转】google谷歌百度收录网站的技巧方法,如何让百度收录?
  7. ping 命令详解
  8. 点点滴滴-ConfigurationManager.AppSettings
  9. IIS由于无法创建应用程序域,因此未能执行请求。错误: 0x80070005 拒绝访问
  10. TeamCity vs Jenkins: Which is the Better Continuous Integration (CI) Server for .NET Software Development?
  11. SQL server学习(一)数据库的基本知识、基本操作(分离、脱机、收缩、备份、还原、附加)和基本语法
  12. 【BZOJ1001】狼抓兔子(网络流)
  13. RESTful levels 和 HATEOAS
  14. 取消IE、Office、Wmp首次开启提示
  15. yii2开启事务
  16. SQL语句内做除法得出百分比
  17. 清华镜像站安装docker
  18. jqzoom插件图片放大功能的一些BUG
  19. POJ2396:Budget(带下界的网络流)
  20. npm模块安装机制

热门文章

  1. LGP5992题解
  2. Java &amp;、&amp;&amp;、|、||、^、&lt;&lt;、&gt;&gt;、~、&gt;&gt;&gt;等运算符
  3. python+pytest接口自动化(9)-cookie绕过登录(保持登录状态)
  4. Spring 中的 bean线程安全性分析
  5. logging 日志模块 configparser 配置文件
  6. 到底为什么不建议使用SELECT *?
  7. leetcode-3无重复字符的最长子串
  8. 什么情况下一个 broker 会从 isr中踢出去?
  9. Docker配置PostgreSQL数据本地持久化
  10. Javascript Range对象的学习