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)把查询的两表结果 ...
随机推荐
- bzoj2730矿场搭建——点双连通分量
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2730 首先一遍tarjan找出割点,将图缩点,这些大点中如果有只包含一个割点的,那么如果这个 ...
- python optparse模块的简单用法
# coding = utf-8 from optparse import OptionParser from optparse import OptionGroup usage = 'Usage: ...
- Identity Server 4 原理和实战(完结)_----选看 OAuth 2.0 简介(上)
https://www.yuque.com/yuejiangliu/dotnet/cg95ni 代表资源所有者的凭据 授权 Authorization Grant 授权是一个代表着资源所有者权限的凭据 ...
- PHP文件操作功能函数大全
PHP文件操作功能函数大全 <?php /* 转换字节大小 */ function transByte($size){ $arr=array("B","KB&quo ...
- UVA - 11624 Fire! 双向BFS追击问题
Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...
- Spring入门(四):使用Maven管理Spring项目
让我们先回顾下本系列的前3篇博客: Spring入门(一):创建Spring项目 Spring入门(二):自动化装配bean Spring入门(三):通过JavaConfig装配bean 1.为什么要 ...
- kuangbin带你飞 - 合集
[题目列表] 之前有一些做过了的,这次从数论开始?
- 萌新笔记之堆(heap)
前言(萌新感想): 以前用STL的queue啊stack啊priority_queue啊,一直很想懂原理,现在终于课上到了priority_queue,还有就是下周期中考,哈哈,所以写几篇blog总结 ...
- 3DMAX 3场景制作
1 模型制作 2 UVW贴图展开 1 打开材质编辑器,给模型一个材质(以后应该以这个材质生成uvw展开,进而生成贴图,贴图绘制完毕后,再贴回这个材质中,就完成了给模型加贴图的操作) 2 在编辑面板中添 ...
- MySql 5.6 遇到的一些问题
1. 卸载5.5之后,使用 mysql installer 时,没法设定 data directory . 最后再次删除mysql installer之后,使系统干净后才能重新安装, 然后界面出现了 ...