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 &lt; #{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 &lt; #{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中的复合条件查询的更多相关文章

  1. 《Entity Framework 6 Recipes》中文翻译系列 (35) ------ 第六章 继承与建模高级应用之TPH继承映射中使用复合条件

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 6-11  TPH继承映射中使用复合条件 问题 你想使用TPH为一张表建模,建模中使 ...

  2. mysql——多表——外连接查询——左连接、右连接、复合条件查询

    ), d_id ), name ), age ), sex ), homeadd ) ); ,,,'nan','beijing'); ,,,'nv','hunan'); ,,,'nan','jiang ...

  3. SQL 中的多条件查询

    在应用程序开发中,多条件查询是个经常遇到的情况,最简单最麻烦的方法是把所有的可能情况都考虑到,但是无疑是繁琐的,而且很容易漏掉可能的情形,下面是SQL语句实现多条件查询的情况 select * fro ...

  4. Linq和EF 做 单一条件查询 和 复合条件 查询 以及 多表 联合查询 示例

    单一条件查询: var table2Object = (from t1 in db.table1 join t2 in db.table2 on t1.id equals t2.id select t ...

  5. MyBatis 中两表关联查询MYSQL (14)

    MyBatis 中两表关联查询MYSQL 1.创建数据库表语句 2.插入测试数据 3.pom文件内容 <?xml version="1.0" encoding="U ...

  6. mybatis中的foreach条件参数过多时,#和$效率比较

    在客户端查询都小于1秒. 测试: mybatis中in条件12.3万数据$ : 6051 ms# : 27045 ms 1.2万数据$ : 1154 ms# : 24387 ms 5 万数据$ : 2 ...

  7. MyBatis无法根据中文条件查询出结果

    情况是这样的 , 以英文做参数可以查询到结果 , 以中文做参数则查询不到结果 在mysql workbench中执行sql , 可以查询到结果. 这是mybatis中没有指定utf-8的缘故导致的. ...

  8. lucene复合条件查询案例——查询name域 或 description域 包含lucene关键字的两种方式

    方式一:使用语法表达式查询 //查询name域 或 description域包含lucene关键字 QueryParser queryParser = new QueryParser("na ...

  9. MyBatis中实现多表查询

    如果查询的数据量大,推荐使用N+1次查询.数据量少使用联合查询... 一. 1.Mybatis是实现多表查询方式 1.1  业务装配:对两个表编写单表查询语句,在业务(Service)把查询的两表结果 ...

随机推荐

  1. python 简易音乐盒子

    #!/usr/bin/env python#-*- coding:utf-8 -*- from Tkinter import *import tkMessageBoximport urllib def ...

  2. redis-cluster的实例动态调整内存

    当redis.conf中的最大内存配置为10G的时候,恰好程序已经写满了,但是物理主机是有内存的, 此时可以通过config set xxxx xxxx 来设置实例的内存大小,而不需要重启实例. 获取 ...

  3. 一:MetaMq集群中单个节点的安装配置示意图

    MetaMQ集群一个节点的安装和配置示意图[1]:下载metaMQ的安装包

  4. IntelliJ IDEA 2018 设置代码提示对大小写不敏感

    setting->Editor->General->Code Completion取消勾选Match case

  5. bzoj 4289 PA2012 Tax——构图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4289 可以把一个点上的边按权值排序,然后边权小的向第一个比它大的连差值的边,边权大的向第一个 ...

  6. Linux 设备树 dts

    1. dtb反编译成dts文件命令:./kernel-4.4/scripts/dtc/dtc_overlay -I dtb -O dts out/target/product/m863ur100_p0 ...

  7. 四、Chrome开发者工具详解(4)-Profiles面板

    摘自: http://www.cnblogs.com/charliechu/p/6003713.html

  8. 注销ie中的ActiveX插件

    最新在C#下开发ActiveX控件,遇到一个问题,就是在调试的时候,ActiveX就已经注册在了调试目录下,这样即使安装这个插件,也无法注册到ActiveX的安装目录下.为了解决这个问题,需要注销下调 ...

  9. Locked Treasure

    题意: 有一宝箱,宝箱上有一些锁,有n个人,每个人分管一些钥匙(每个锁对应无数个钥匙), 现给出n,m 求问至少需要多少锁才能存在一种钥匙分配方案使得: 1.至少m个人才可以打开锁. 2.任选m个人一 ...

  10. npm和package.json那些不为常人所知的小秘密

    此文已由作者黄锴授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 强大的命令功能 如果你没使用过script,那你可算是从来没手动编辑过package.json.script作 ...