mapper接口

public interface EmpMapper {

    List<Emp> getEmp(Emp emp);
}

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="com.xxx.dynamicSQL.mapper.EmpMapper"> <!--
if标签:通过test属性中的表达式判断标签中的内容是否有效(是否会拼接到sql中)
where标签:1.若where标签中有条件成立,会自动生成where关键字
2.会自动将where标签中内容前多余的and去掉,但是其中内容后多余的and无法去掉
3.若where标签中没有任何一个条件成立,则where也不会自动生成
-->
<select id="getEmp" resultType="emp">
select * from t_emp
<where>
<if test="empName != null and empName != ''">
and emp_name = #{empName}
</if>
<if test="age != null and age != ''">
and age = #{age}
</if>
<if test="gender != null and gender != ''">
and gender = #{gender}
</if>
</where>
</select>
</mapper>

测试代码

@Test
public void test1(){
SqlSession sqlSession = SqlSessionUtil.getSqlSession();
EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
Emp emp = new Emp(null,"李四",null,"男");
List<Emp> list = mapper.getEmp(emp); list.forEach(System.out::println);
}

最新文章

  1. 使用MapReduce实现join操作
  2. my_mosaic
  3. redis 学习笔记(5)-Spring与Jedis的集成
  4. WINCE+6410 拨号上网
  5. SharePoint2013 SharePoint-Hosted 模式 分页方法
  6. source和.命令的区别
  7. eclipse import的项目报autowired cannot be resolved to a type的错误
  8. phpstorm配置Xdebug进行调试PHP教程
  9. UINavigationController和UITabBarController合用
  10. Delphi总结使用TStrings的一些技巧
  11. 使用tortoisegit工具git地址中带号码密码的拉取,以及使用这种方式后中途重置密码报git remote: HTTP Basic: Access denied 错误解决办法
  12. java8_api_字符串处理
  13. php过滤&amp;nbsp;字符
  14. tkinter之grid布局管理器详解
  15. json对象转数组
  16. PythonStudy——字符编码 Character Encoding
  17. Django REST framework 源码剖析
  18. 多线程 Runnable 实现线程 内部类
  19. BZOJ 2434 阿狸的打字机(fail树)
  20. ubuntu 安装php 报错解决

热门文章

  1. 第三篇:前端基础之JavaScript
  2. 带你读AI论文丨针对文字识别的多模态半监督方法
  3. python 学生管理系统 文件版 增删改查
  4. eclipse启动一个Springboot项目
  5. 在 C# 9 中使用 foreach 扩展
  6. [剑指Offer]3.数组中重复的数字
  7. 交叉编译esp8089
  8. excel文件 实现自动处理数据的功能
  9. 微机原理与系统设计笔记2 | 8086CPU结构与功能
  10. angular11报错Can&#39;t bind to &#39;ngForOf&#39; since it isn&#39;t a known property of &#39;tr&#39;. 三种排查办法以及解决方案