Mybatis中的复合条件查询
1.Map中根据字段名存儲:
定义接口:List<Student> selectByCondition1(Map<String,Object> map);
映射文件:
<select id="selectByCondition1" resultType="com.framework.entity.Student">
select * from stu
where name like '%' #{name} '%' and age < #{age}
</select>
测试类:
public void test(){
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", "Yang");
map.put("age", "17");
List<Student> students = dao.selectByCondition(map);
for (Student student : students){
System.out.println(student);
}
}
2.Map中存儲对象
定义接口:List<Student> selectByCondition2(Map<String,Object> map);
映射文件:
<select id="selectByCondition2" resultType="com.framework.entity.Student">
select * from stu
where name like '%' #{stu1.name} '%' and age < #{stu2age}
</select>
测试类:
public void test(){
Map<String,Object> map = new HashMap<String,Object>();
Student stu1 = new Student();
Student stu2 = new Student();
map.put("stu1", stu1);
map.put("stu2", stu2);
List<Student> students = dao.selectByCondition(map);
for (Student student : students){
System.out.println(student);
}
}
Mybatis中的复合条件查询的更多相关文章
- 《Entity Framework 6 Recipes》中文翻译系列 (35) ------ 第六章 继承与建模高级应用之TPH继承映射中使用复合条件
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 6-11 TPH继承映射中使用复合条件 问题 你想使用TPH为一张表建模,建模中使 ...
- mysql——多表——外连接查询——左连接、右连接、复合条件查询
), d_id ), name ), age ), sex ), homeadd ) ); ,,,'nan','beijing'); ,,,'nv','hunan'); ,,,'nan','jiang ...
- SQL 中的多条件查询
在应用程序开发中,多条件查询是个经常遇到的情况,最简单最麻烦的方法是把所有的可能情况都考虑到,但是无疑是繁琐的,而且很容易漏掉可能的情形,下面是SQL语句实现多条件查询的情况 select * fro ...
- Linq和EF 做 单一条件查询 和 复合条件 查询 以及 多表 联合查询 示例
单一条件查询: var table2Object = (from t1 in db.table1 join t2 in db.table2 on t1.id equals t2.id select t ...
- MyBatis 中两表关联查询MYSQL (14)
MyBatis 中两表关联查询MYSQL 1.创建数据库表语句 2.插入测试数据 3.pom文件内容 <?xml version="1.0" encoding="U ...
- mybatis中的foreach条件参数过多时,#和$效率比较
在客户端查询都小于1秒. 测试: mybatis中in条件12.3万数据$ : 6051 ms# : 27045 ms 1.2万数据$ : 1154 ms# : 24387 ms 5 万数据$ : 2 ...
- MyBatis无法根据中文条件查询出结果
情况是这样的 , 以英文做参数可以查询到结果 , 以中文做参数则查询不到结果 在mysql workbench中执行sql , 可以查询到结果. 这是mybatis中没有指定utf-8的缘故导致的. ...
- lucene复合条件查询案例——查询name域 或 description域 包含lucene关键字的两种方式
方式一:使用语法表达式查询 //查询name域 或 description域包含lucene关键字 QueryParser queryParser = new QueryParser("na ...
- MyBatis中实现多表查询
如果查询的数据量大,推荐使用N+1次查询.数据量少使用联合查询... 一. 1.Mybatis是实现多表查询方式 1.1 业务装配:对两个表编写单表查询语句,在业务(Service)把查询的两表结果 ...
随机推荐
- CodeForces990G:GCD Counting(树分治+GCD)
You are given a tree consisting of nn vertices. A number is written on each vertex; the number on ve ...
- css 内容超出宽度自动换行
1. word-break:break-all;只对英文起作用,以字母作为换行依据2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 PS:要设定宽度!
- AutoIt:如何处理应用程序端口被占用的情况
为公司的部署工程师书写了一个autoIt应用程序,现在遇到下面的一种情况: 产品分服务器端和客户端,启动的时候,会启用1785端口,然后彼此通信: 现在我的autoIt应用程序需要做的事情是: 如果1 ...
- Win32编程点滴3 - 简单ActiveX控件的使用
虽然这里一片的.net气氛,到处充斥着像MVC.WPF.WorkFlow.LINQ等各种niubility的术语.但我们使用的Windows还是由COM技术主宰着:我们在选择日常使用的软件时,也会避免 ...
- bzoj2257瓶子与燃料——最大公约数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2257 可以知道最终能够导出的燃料一定是瓶子容量的gcd的倍数,所以此题转化为求n个数中k个数 ...
- SQL SERVER2008 打开脚本总是报“未能完成操作,存储空间不足”
使用用SQLCMD命令行. 1.快捷键:win+R 2.输入cmd,确定 3.输入命令:sqlcmd -S <数据库服务器名称> -i C:\<脚本文件路径>.sql 如图所 ...
- android自动化测试之uiautomator
1.通过monkeyrunner.bat monkey_record.py启动MonkeyRecorder进行拿到各个控件的坐标(要连上手机才可以启动) 2.也可以通过uiautomatorvie ...
- SQLite win7
https://blog.csdn.net/louislee92/article/details/50390000 vs2008利用sqlite A 添加sqlite3.h sqlite3.lib到工 ...
- 生产环境下Flask项目目录构建
接触Flask已经有大半年了,本篇博客主要来探讨如何规范化生产环境下Flask的项目目录结构.虽然目录结构见仁见智,个人有个人的看法和习惯,但总的来说,经过很多人的实践和总结,还是有很多共同的意见和想 ...
- 激光SLAM
1.激光分类 维度分类: a.二维激光(单点反射.平面.旋转台) b.三维激光 距离分类: a.近距离:壁障.碰撞检测.路边检测 b.远距离:行人检测.定位.建图 特点: 优点: a.可以直接获取深度 ...