MyBatis Generator产生的Example类
来源:互联网 发布:js object to number 编辑:程序博客网 时间:2024/06/05 22:57
MyBatis Generator产生的Example类
Example类用于构造复杂的筛选条件。
基本概念
- Criterion
Criterion是最基本,最底层的Where条件,用于字段级的筛选,feild用于指代字段名字,列举如下:
只有一个条件,不需要其他参考值
feild IS NOLL
feild IS NOT NULL与一个参考值进行算数运算
feild > value
feild >= value
feild = value
feild <> value
feild <= value
feild < value与一个参考值进行模糊查询,参值中的%,?只能在构造查询条件时手动指定。
feild LIKE value
feild NOT LIKE value介于两个参考值之间
feild BETWEEN value AND secondValue
在或不在一个参考值集合中,item来自于value集合
feild IN (item,item,item,...)
feild NOT IN (item,item,item,...)MyBatis Generator会为每个字段产生如上的Criterion,如果表的字段比较多,产生的Example类会十分庞大。理论上通过Example类可以构造你想到的任何筛选条件。
- Criteria
Criteria包含一个Cretiron的集合,每一个Criteria对象内包含的Cretiron之间是由AND连接的,是逻辑与的关系。
- oredCriteria
Example内有一个成员叫oredCriteria,是Criteria的集合,就想其名字所预示的一样,这个集合中的Criteria是由OR连接的,是逻辑或关系。oredCriteria就是ORed Criteria。
用法
示例来自官方文档。
TestTableExample example =
new
TestTableExample();
example.or()
.andField1EqualTo(
5
)
.andField2IsNull();
example.or()
.andField3NotEqualTo(
9
)
.andField4IsNotNull();
List<Integer> field5Values =
new
ArrayList<Integer>();
field5Values.add(
8
);
field5Values.add(
11
);
field5Values.add(
14
);
field5Values.add(
22
);
example.or()
.andField5In(field5Values);
example.or()
.andField6Between(
3
,
7
);
or()方法会产生一个新的Criteria对象,添加到oredCriteria中,并返回这个Criteria对象,从而可以链式表达,为其添加Criterion。
产生的动态SQL是这样的:
where
(field1 = 5
and
field2
is
null
)
or
(field3 <> 9
and
field4
is
not
null
)
or
(field5
in
(8, 11, 14, 22))
or
(field6
between
3
and
7)
其他
Example类的distinct字段用于指定DISTINCT查询。
orderByClause字段用于指定ORDER BY条件,这个条件没有构造方法,直接通过传递字符串值指定。
配置Mybatis Generator不要生成Example类
Mybatis Generator默认设置会生成一大堆罗哩罗嗦的Example类,主要是用各种不同的条件来操作数据库,大部分是用不到的,用到的时候手工修改mapper和接口文件就行了。
<
table
schema
=
"general"
tableName=
"tb_table_name"
domainObjectName=
"EntityName"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId=
"false"
>
<property
name
=
"useActualColumnNames"
value=
"true"
/>
</
table
>
这样生成的mapper和dao接口就清爽多了。
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类
- MyBatis Generator产生的Example类说明
- mybatis generator利用example类的生成配置
- mybatis generator生成的**Example类具体用法
- 去掉Mybatis Generator生成的一堆 example
- 去掉Mybatis Generator生成的一堆 example
- 去掉Mybatis Generator生成的一堆 example
- 去掉Mybatis Generator生成的一堆 example
- 配置Mybatis Generator不要生成Example类
- 高效Linux bash快捷键及alias总结
- 程序运行超时处理——JAVA
- 关于file_operations结构体
- Vaadin Web应用开发教程(21):UI组件-Embedded组件
- mysql行锁和表锁
- MyBatis Generator产生的Example类
- [Android 基础知识] 之十二: 广播的两种发送方式
- 梁漱溟:做学问的八层境界
- Linux下编写 jar包自动启动脚本
- 快速排序
- FF上selenium IDE的基础知识--Accessors命令
- HDU - 2256 Problem of Precision 矩阵快速幂
- spring interceptor
- android textview 利用空格实现文字均匀分布