满足条件的数据
mapper.xml 满足if条件就执行,不满足就不加
<select id="selectStateByTitle" parameterType="string" resultMap="blogResultMap">
select * from blog
where state = "1"
<if test="value != null and value != ''">
and title like '%${value}%'
</if>
 
</select>
接口:mapper
List<Blog> selectStateByTitle(String title);
测试 test 可以写满足的条件也可以不写
@Test
public void testSelectStateByTitle(){
SqlSession session = MybatisUtil.getSqlSession();
BlogMapper blogMapper = session.getMapper(BlogMapper.class);
List<Blog> blogList = blogMapper.selectStateByTitle(null);
session.close();
 
System.out.println("<<<<<------ 查询------>>>>>:"+blogList);
}
 
实际应用在代码中
 <select id="findList" resultType="Periodical">
         SELECT
             <include refid="periodicalColumns"/>
         FROM periodical a
         <include refid="periodicalJoins"/>
         <where>
             a.del_flag = #{DEL_FLAG_NORMAL}
             <if test="type != null and type != ''">
                 AND  type = #{type}
             </if>
             <if test="name != null and name != ''">
                 AND a.name LIKE
                     <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
                     <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
                     <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
             </if>
         </where>
         <choose>
             <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                 ORDER BY ${page.orderBy}
             </when>
             <otherwise>
                 ORDER BY a.update_date DESC
             </otherwise>
         </choose>
     </select>
     

最新文章

  1. 【先定一个小目标】Windows下Redis的安装使用
  2. [WPF系列] window自定义
  3. java变量的加载顺序
  4. 解决 HttpClient 模拟 http 的get 请求后 ,出现 403 错误
  5. Lucas
  6. u盘在电脑读不出来,但别的可以读,别的u盘在我电脑又可以识别怎么回事?
  7. 反转(开关问题) POJ 3276
  8. MsSql省市联动表
  9. Java访问kafka的时候java.nio.channels.ClosedChannelException解决办法
  10. Unique Binary Search Trees II 解答
  11. docker exec 运行命令
  12. hdu1260(dp)
  13. robot framework -重点记录
  14. [Swift]LeetCode373. 查找和最小的K对数字 | Find K Pairs with Smallest Sums
  15. android的listview以及画线--to thi tha
  16. aop技术理解使用
  17. 用360清理了一下电脑后发现Eclipse软件无法打开
  18. YARN集群的mapreduce测试(四)
  19. h.264并行熵解码
  20. 『转』MySQL存储过程语法例子

热门文章

  1. .Net 使用 GregorianCalendar 获取任意一天为一年的第几周
  2. ConfigureAwait(false)
  3. xcode编译静态库选择cpu架构
  4. java连接字符串操作,可用来向sql传值
  5. hadoop再次集群搭建(4)-Cloudera Manager Installation
  6. 关于handler的再次讨论
  7. [codevs1159]最大全0子矩阵(悬线法)
  8. NSSelectorFromString 使用示例
  9. Log4Net 调试时输出sql到 视图-&gt;输出的sql语句
  10. hadoop运行故障问题解决1——datanode节点启动后自动关闭