SSM-MyBatis-13:Mybatis中多条件查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
实体类
public class Book {
private Integer bookID;
private String bookName;
private String bookAuthor;
private Integer bookPrice;
public Book() {
}
public Integer getBookID() {
return this.bookID;
}
public void setBookID(Integer bookID) {
this.bookID = bookID;
}
public String getBookName() {
return this.bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getBookAuthor() {
return this.bookAuthor;
}
public void setBookAuthor(String bookAuthor) {
this.bookAuthor = bookAuthor;
}
public Integer getBookPrice() {
return this.bookPrice;
}
public void setBookPrice(Integer bookPrice) {
this.bookPrice = bookPrice;
}
}
接口中的方法
俩种形式,一种采用map,一种采用直接参数Index(索引的方式)来实现的多条件查询
//根据多条件查询map版
public List<Book> findtrueBookMap(Map<String,Object> map);
//根据多条件查询index版
public List<Book> findtrueBookIndex(String bookName,Integer bookPrice);
小配置中
<!--多条件查询map版-->
<select id="findtrueBookMap" resultType="Book">
select * from book WHERE bookName LIKE '%' #{bookName} '%' AND bookPrice>#{bookPrice}
</select>
<!--多条件查询Index版-->
<select id="findtrueBookIndex" resultType="Book">
select * from book WHERE bookName LIKE '%' #{} '%' AND bookPrice>#{}
</select>
测试类中
///多条件查询Index版
@Test
public void t4selectmoreIndex(){
SqlSession session= MyBatisUtils.getSession(); IBookDAO mapper = session.getMapper(IBookDAO.class);
List<Book> books = mapper.findtrueBookIndex("心",);
for (Book items:books) {
System.out.println(items.getBookName());
} session.close(); } ///多条件查询map版
@Test
public void t3selectmoreMap(){
SqlSession session= MyBatisUtils.getSession(); IBookDAO mapper = session.getMapper(IBookDAO.class);
Map<String,Object> map=new HashMap<String,Object>();
map.put("bookName","心");
map.put("bookPrice",);
List<Book> books = mapper.findtrueBookMap(map);
for (Book items:books) {
System.out.println(items.getBookName());
} session.close(); }
这块要解释的真的没有些什么,先照猫画虎,会用,知道每出该填什么,入们后再去想其他,有些从字面意思就可以理解,有些则是就应该这么写,mybatis中独特的写法,就像java中的关键字,理解就好
SSM-MyBatis-13:Mybatis中多条件查询的更多相关文章
- C# 将Access中时间段条件查询的数据添加到ListView中
C# 将Access中时间段条件查询的数据添加到ListView中 一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Col ...
- Hibernate中的条件查询完成类
Hibernate中的条件查询有以下三个类完成: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类
- ormlite 在android中 排序 条件查询
ormlite 在android中 排序 条件查询 all = dao.queryBuilder().orderBy("Id", true).where().eq("Ty ...
- Hibernate中的条件查询完毕类
Hibernate中的条件查询有下面三个类完毕: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类
- Mybatis-技术专区-中的条件查询createCriteria example里面的条件
之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...
- 具有SSM框架的CRUD与多条件查询
概述 居于ssm版本的crud跟多添加查询, 并带分页的demo 详细 代码下载:http://www.demodashi.com/demo/13653.html 一.功能展示 部门CRUD: 员工C ...
- SQL中多条件查询括号的用途
界面: 代码 0 posted @ 2009-12-15 13:28 唔愛吃蘋果 阅读(8640) 评论(0) 编辑 收藏
- ThinkPHP中 按条件查询后列表显示
最近在项目中遇到了需要根据下拉框的条件筛选出符合条件的数据,然后进行列表显示的问题. 在ThinkPHP中进行列表显示的传统过程:通过在后台控制器中查询出数据,然后通过$this->assign ...
- 【.Net】C# 将Access中时间段条件查询的数据添加到ListView中
一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字. 二.利用代码给ListView添加 ...
随机推荐
- 调用bios喇叭发声
话不多说,上代码: #include <windows.h> #include <iostream> #include <map> using namespace ...
- Android Bootloader LittleKernel的两篇文章
Android 开发之 ---- bootloader (LK) LK是什么 LK 是 Little Kernel 它是 appsbl (Applications ARM Boot Loader)流程 ...
- HBase 快照操作
1.配置hbase-site.xml <property> <name>hbase.snapshot.enabled</name> <value>tru ...
- Erlang cowboy 处理简单的HTTP请求
Erlang cowboy 处理简单的HTTP请求 原文出自: Handling plain HTTP requests 处理请求的最简单的方式是写一个简单的HTTP处理器.它的模型参照Erlang/ ...
- HBase 运维分析
问题分析的主要手段 1.监控系统:首先用于判断系统各项指标是否正常,明确系统目前状况 2.服务端日志:查看例如region移动轨迹,发生了什么动作,服务端接受处理了哪些客户端请求. 3.gc日志:gc ...
- 脚本自动化 ant
用ant,shell下也可以用make. 1,ant 是一个自动化编译工具,安装使用. 2,编写build.xml,核心,写明进行哪些操作,删,建,编译,javac,java等,从例子可以看出每个操作 ...
- Android BLE与终端通信(二)——Android Bluetooth基础科普以及搜索蓝牙设备显示列表
Android BLE与终端通信(二)--Android Bluetooth基础搜索蓝牙设备显示列表 摘要 第一篇算是个热身,这一片开始来写些硬菜了,这篇就是实际和蓝牙打交道了,所以要用到真机调试哟, ...
- PS 色调——老照片效果
这就是通过调色使照片显得发黄. R_new=0.393*R+0.769*G+0.189*B; G_new=0.349*R+0.686*G+0.168*B; B_new=0.272*R+0.534*G+ ...
- 【38】java的集合框架(容器框架)
Collection接口 Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements).一些 Collection允许相同的元 ...
- LeetCode(63)-First Bad Version
题目: You are a product manager and currently leading a team to develop a new product. Unfortunately, ...