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添加 ...
随机推荐
- 《java入门第一季》之参数引用
Java中的参数传递问题: 基本类型:形式参数的改变对实际参数没有影响. 引用类型:形式参数的改变直接影响实际参数. */ class ArgsDemo { public static void ma ...
- AP INVOICES IMPORT API(NOT request)
PROCEDURE process_cux_to_ap(x_return_status OUT NOCOPY VARCHAR2, x_msg_count OUT NOCOPY NUMBER, x_ms ...
- TrueType字体的后缀名解释
OpenType标准定义了OpenType文件名称的后缀名.包含TureType字体的OpenType文件后缀名为.ttf,包含PostScript字体的文件后缀名为.OTF.如果是包含一系列True ...
- Customer Form Issue: Automatic Matching Rule Set Defaults Value AutoRuleSet-1
In this Document Symptoms Changes Cause Solution References APPLIES TO: Oracle Receivables ...
- TinySpring分析二
step5 看完了前面的几步,到现在我们必然要想到的问题就是,数据要是放在xml中怎么读? 其实按照正常思维一步一步来,从xml中读数据和之前手工配进去并没有什么大的区别,只要读出来就OK了. 先看测 ...
- PHP 与搜索蜘蛛
本文移到:http://www.phpgay.com/Article/detail/classid/2/id/63.html
- Oracle EBS订单的流程(Order->AR)
from:http://blog.csdn.net/pan_tian/article/details/7693447 基本流程 创建订单 路径:Order Management > Orders ...
- 【Android 应用开发】BluetoothAdapter解析
这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每个常量含义. 一 BluetoothAdapter简介 1.继承关系 该类仅继承了Object类; 2.该类作用 ...
- Android ViewPager和Slidingmenu手势冲突问题
尊重原创: http://blog.csdn.net/sk719887916/article/details/40043961 skay 想必大家都遇到过手势和焦点的问题 对于安卓初学者或者初次 ...
- leetcode之旅(7)-Move Zeroes
Move Zeroes 题目描述: Given an array nums, write a function to move all 0's to the end of it while maint ...