Example解析
2024-09-01 17:07:58
本文总结自:https://github.com/abel533/Mapper/wiki/6.example,旨在提供一些基本概念上的解释
Example类用于条件查询,以代替冗长的"select from xxxxxx"
Example可分为两类
1、MBG生成的Example
例如:
CountryExample example = new CountryExample();
example.createCriteria().andCountrynameLike("A%"); //无需设置属性名,此处为给名为CountryName的属性设值
example.or().andIdGreaterThan(100);
example.setDistinct(true);
int count = mapper.deleteByExample(example);//这是一个Example方法
备注:criteria相当于条件查询中的"where xxx"
MBG提供的Example与model中的类的类名对应
2、通用Mapper提供的通用Example
通用Mapper 提供的一个类,这个类和 MBG 生成的相比,需要自己设置属性名。这个类还额外提供了更多的方法。
例如:
Example example = new Example(Country.class); //提供类名
example.setForUpdate(true);
example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151);
example.or().andLessThan("id", 41);
List<Country> countries = mapper.selectByExample(example);
-------------------------------------------------------------------------------------------------------------------------------
Example方法(即mapper如何使用example的方法)
方法有许多,有两种类型的定义方式:
List<T> selectByExample(Object example); int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);
所有Example方法中的example类型都是Object
类型,这是因为通用 Mapper 支持所有符合Example结构的参数。
例如通过MBG生成的CountryExample、UserExample类。还有通用Mapper中提供的通用Example,以及支持Java8方法引用的Weekend类型。
最新文章
- Android经典完美退出方法
- Jedis下的ShardedJedis(分布式)使用方法(一)
- 在Winform中播放视频等【DotNet,C#】
- iOS中Block使用探索
- 用C#.NET调用Java开发的WebService传递int,double问题
- BFS-hdu-1226-超级密码
- php注册登录时生成的验证码
- 【USACO 3.1.6】邮票
- Linux系统编程(33)—— socket编程之TCP程序的错误处理
- C++读写文件流的相关介绍
- 【BZOJ1791】【IOI2008】【基环树】island(status第一速度)
- Chrome浏览器扩展开发系列之十:桌面通知Notification
- Linux必知必会的目录与启动过程
- Unity服务端链接MySQL数据库
- Alpha冲刺第十二天
- asp.net中的Filter类型其实是被当作单例的
- keepalived高可用系列~keepalived+mysql
- 【iCore1S 双核心板_ARM】例程二:读取ARM按键状态
- SuperMap开发入门4——保存的坑
- laya IDE 初始化设置
热门文章
- PyQt4消息窗口
- Swift-&#39;as?&#39;,&#39;as&#39;用法
- Docker源码分析(三):Docker Daemon启动
- 腾讯云CMQ消息队列在Windows环境下的使用
- 正则表达式—RegEx(RegularExpressio)(一)
- spring低版本报错:java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [*] are only available on
- thinkphp---定义前台视图模板
- DCloud开发资源链接
- 解决IE7下scroll的bug
- spring boot web服务