mapper自动生成复杂表达式的多条件查询
来源:互联网 发布:matlab plot函数矩阵 编辑:程序博客网 时间:2024/05/21 07:49
import
java.io.IOException;
import
java.io.Reader;
import
java.util.ArrayList;
import
java.util.List;
import
org.apache.ibatis.io.Resources;
import
org.apache.ibatis.session.SqlSession;
import
org.apache.ibatis.session.SqlSessionFactory;
import
org.apache.ibatis.session.SqlSessionFactoryBuilder;
import
org.apache.log4j.pattern.ClassNamePatternConverter;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import
cn.itcast.ssm.mapper.ItemsMapper;
import
cn.itcast.ssm.po.ItemsExample;
public
class
Student {
public
static
void main(
String
[] args) throws IOException {
/*方式一 */
ItemsExample itemsExample1 =
new
ItemsExample();
itemsExample1.
or
().andIdEqualTo(
5
).andNameIsNotNull();
itemsExample1.
or
().andPicEqualTo(
"xxx"
).andPicIsNull();
List<
Integer
> fieldValues =
new
ArrayList<
Integer
>();
fieldValues.add(
8
);
fieldValues.add(
11
);
fieldValues.add(
14
);
fieldValues.add(
22
);
itemsExample1.
or
().andIdIn(fieldValues);
itemsExample1.
or
().andIdBetween(
5
,
9
);
/* 方式二 criteria1与criteria2是or的关系 */
ItemsExample itemsExample2 =
new
ItemsExample();
ItemsExample.Criteria criteria1 = itemsExample2.createCriteria();
criteria1.andIdIsNull();
criteria1.andPriceEqualTo((float)
3
);
ItemsExample.Criteria criteria2 = itemsExample2.createCriteria();
criteria2.andNameIsNull();
criteria2.andIdGreaterThanOrEqualTo(
5
);
itemsExample2.
or
(criteria2);
//方式一和方式二是等价的
// spring获取mapper代理对象
ApplicationContext applicationContext =
new
ClassPathXmlApplicationContext(
"classpath:applicationContext.xml"
);
ItemsMapper itemsMapper = (ItemsMapper) applicationContext.getBean(
"itemsMapper"
);
itemsMapper.countByExample(itemsExample2);
// 获取SqlSessionFactory
String
resource =
"SqlMapConfig.xml"
;
Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlMapper =
new
SqlSessionFactoryBuilder().build(reader);
// 获取SqlSession
SqlSession sqlSession = sqlMapper.openSession();
}
}
阅读全文
0 0
- mapper自动生成复杂表达式的多条件查询
- 复杂条件的查询
- mybatis利用mapper代理的方法实现多条件查询
- mapper时间条件查询
- mybatis自动生成mapper.xml的方法
- 条件复杂的sql语句查询
- mybatis 自动生成 mapper
- C#连接SQL多条件复杂查询
- 复杂搜索条件查询
- 复杂条件查询
- 查询条件解析类,生成查询语句的查询条件
- MongoTemplate针对多条件查询以及复杂查询基本示例
- mybatis-mapper的复杂映射
- EAS 在自动生成的查询中加自定义的条件
- 3.Python进阶-切片+列表生成式+复杂表达式+条件过滤+多层表达式
- mybatis + maven 自动生成mapper
- SpringBoot自动生成Mapper映射
- MyBatista Generator自动生成mapper
- java中TimeUnit vs Thread.sleep的用法对比
- Ubuntu 16.04安装Nvidia 驱动及cuda 8.0 cudnn6.0 遇到的坑
- 铁 警 思——灵宝西站派出所第一警务区:张千
- redis有效时间设置及时间过期处理
- 鸟哥采访截取一段
- mapper自动生成复杂表达式的多条件查询
- TRSWCMV7 置标取值判断是否为空,为空给默认值,不为空取字段原值
- 基于Node.js+express+MySQL+Bootstrap实现的简单登录注册
- SLAM学习之《State Estimation for Robotics》——2.1.1
- java8实战十:CompletableFuture 组合式异步编程
- 工欲善其事必先利其器
- 适配器圆形的
- 关于大型网站技术演进的思考(十九):网站静态化处理—Web前端优化—上(11)
- Kafka producer无法发送消息解决办法