------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

实体类

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中多条件查询的更多相关文章

  1. C# 将Access中时间段条件查询的数据添加到ListView中

    C# 将Access中时间段条件查询的数据添加到ListView中 一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Col ...

  2. Hibernate中的条件查询完成类

    Hibernate中的条件查询有以下三个类完成: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类

  3. ormlite 在android中 排序 条件查询

    ormlite 在android中 排序 条件查询 all = dao.queryBuilder().orderBy("Id", true).where().eq("Ty ...

  4. Hibernate中的条件查询完毕类

    Hibernate中的条件查询有下面三个类完毕: 1.Criteria:代表一次查询 2.Criterion:代表一个查询条件 3.Restrictions:产生查询条件的工具类

  5. Mybatis-技术专区-中的条件查询createCriteria example里面的条件

    之前用Mybatis框架反向的实体,还有实体里面的Example,之前只是知道Example里面放的是条件查询的方法,可以一直不知道怎么用,到今天才开始知道怎么简单的用. 在我们前台查询的时候会有许多 ...

  6. 具有SSM框架的CRUD与多条件查询

    概述 居于ssm版本的crud跟多添加查询, 并带分页的demo 详细 代码下载:http://www.demodashi.com/demo/13653.html 一.功能展示 部门CRUD: 员工C ...

  7. SQL中多条件查询括号的用途

    界面: 代码 0 posted @ 2009-12-15 13:28 唔愛吃蘋果 阅读(8640) 评论(0)  编辑 收藏

  8. ThinkPHP中 按条件查询后列表显示

    最近在项目中遇到了需要根据下拉框的条件筛选出符合条件的数据,然后进行列表显示的问题. 在ThinkPHP中进行列表显示的传统过程:通过在后台控制器中查询出数据,然后通过$this->assign ...

  9. 【.Net】C# 将Access中时间段条件查询的数据添加到ListView中

    一.让ListView控件显示表头的方法 在窗体中添加ListView 空间,其属性中设置:View属性设置为:Detail,Columns集合中添加表头中的文字. 二.利用代码给ListView添加 ...

随机推荐

  1. Gradle 1.12用户指南翻译——第二十四章. Groovy 插件

    其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...

  2. 求剁手的分享,如何简单开发js图表

    前段时间做的一个项目里需要用到js图表,在网上找了下,大概找到了highcharts.fusioncharts这些国外产品. 因为都收费,虽然有盗版,我也不敢用,万一被找上们来就砸锅卖铁了要.自己写j ...

  3. Android性能优化之界面UI篇

    1.使用style.color.string.dimen样式来分离xml布局文件,减少代码的重复使用,增加代码复用率,防止hardcode,下面是一个例子: 在定义layout时候,因为每个View或 ...

  4. D-BUS详细分析

    转:http://blog.csdn.net/yclzh0522/article/details/7090599 一.概述 官方网站:http://www.freedesktop.org/wiki/S ...

  5. iOS监听模式系列之推送消息通知

    推送通知 和本地通知不同,推送通知是由应用服务提供商发起的,通过苹果的APNs(Apple Push Notification Server)发送到应用客户端.下面是苹果官方关于推送通知的过程示意图: ...

  6. C++之标准输入输出

    由于在公司,无法上传图片,往后补上. 关于C++的标准输入输出,其实就相当于C语言的scanf和printf,只不过C++用cin和cout这样称为流的机制. #include <iostrea ...

  7. 【Qt编程】基于Qt的词典开发系列<十二>调用讲述人

    我们知道,win7系统自带有讲述人,即可以机器读出当前内容,具体可以将电脑锁定,然后点击左下角的按钮即可.之前在用Matlab写扫雷游戏的时候,也曾经调用过讲述人来进行游戏的语音提示.具体的Matla ...

  8. Gathering Initial Troubleshooting Information for Analysis of ORA-4031 Errors on the Shared Pool

    In this Document   Purpose   Troubleshooting Steps   References APPLIES TO: Oracle Database - Enterp ...

  9. shell中关于sort的-o选项

    sort -o选项意思为将排序后的结果写入文件,但你可能会说我可以重定向啊: sort >file 但如果你要排序文件names里的行再写回排序后的结果: sort names > nam ...

  10. mysql 无法插入中文

    MySQL数据库默认编码已经是utf8了, default-character-set = utf8,可是向数据库中表中插入中文时,却老是出现 ....\xB5\xA5\xD1\xA1 for col ...