File tree Expand file tree Collapse file tree 5 files changed +57
-2
lines changed
src/main/java/tk/mybatis/mapper Expand file tree Collapse file tree 5 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -122,8 +122,8 @@ MyBatis 工具网站:[http://mybatis.tk](http://www.mybatis.tk)
122
122
123
123
作者邮箱: abel533@gmail.com
124
124
125
- MyBatis QQ 群 : <a target =" _blank " href =" http://shang.qq.com/wpa/qunwpa?idkey=7c2f018e4cddc7d4aad04fc312b2d69361a0a896a4f59219a7914953a57bffc2 " ><img border =" 0 " src =" http://pub.idqqimg.com/wpa/images/group.png " alt =" Mybatis工具群(2) " title =" Mybatis工具群(2) " ></a >
125
+ Mybatis工具群(推荐) : <a target =" _blank " href =" http://shang.qq.com/wpa/qunwpa?idkey=7c2f018e4cddc7d4aad04fc312b2d69361a0a896a4f59219a7914953a57bffc2 " ><img border =" 0 " src =" http://pub.idqqimg.com/wpa/images/group.png " alt =" Mybatis工具群(2) " title =" Mybatis工具群(2) " ></a >
126
126
127
- Mybatis工具群: <a target =" _blank " href =" http://shang.qq.com/wpa/qunwpa?idkey=29e4cce8ac3c65d14a1dc40c9ba5c8e71304f143f3ad759ac0b05146e0952044 " ><img border =" 0 " src =" http://pub.idqqimg.com/wpa/images/group.png " alt =" Mybatis工具 " title =" Mybatis工具 " ></a >
127
+ Mybatis工具群(2000 人已满) : <a target =" _blank " href =" http://shang.qq.com/wpa/qunwpa?idkey=29e4cce8ac3c65d14a1dc40c9ba5c8e71304f143f3ad759ac0b05146e0952044 " ><img border =" 0 " src =" http://pub.idqqimg.com/wpa/images/group.png " alt =" Mybatis工具 " title =" Mybatis工具 " ></a >
128
128
129
129
推荐使用Mybatis分页插件:[ PageHelper分页插件] ( https://github.com/pagehelper/Mybatis-PageHelper )
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ public class Example implements IDynamicTableName {
51
51
52
52
protected Set <String > selectColumns ;
53
53
54
+ protected String countColumn ;
55
+
54
56
protected List <Criteria > oredCriteria ;
55
57
56
58
protected Class <?> entityClass ;
@@ -194,6 +196,21 @@ public Example selectProperties(String... properties) {
194
196
return this ;
195
197
}
196
198
199
+ public String getCountColumn () {
200
+ return countColumn ;
201
+ }
202
+
203
+ /**
204
+ * 指定 count(property) 查询属性
205
+ *
206
+ * @param property
207
+ */
208
+ public void setCountProperty (String property ) {
209
+ if (propertyMap .containsKey (property )) {
210
+ this .countColumn = propertyMap .get (property ).getColumn ();
211
+ }
212
+ }
213
+
197
214
public boolean isDistinct () {
198
215
return distinct ;
199
216
}
Original file line number Diff line number Diff line change @@ -525,6 +525,28 @@ public static String exampleSelectColumns(Class<?> entityClass) {
525
525
return sql .toString ();
526
526
}
527
527
528
+ /**
529
+ * example支持查询指定列时
530
+ *
531
+ * @return
532
+ */
533
+ public static String exampleCountColumn (Class <?> entityClass ) {
534
+ StringBuilder sql = new StringBuilder ();
535
+ sql .append ("<choose>" );
536
+ sql .append ("<when test=\" @tk.mybatis.mapper.util.OGNL@hasCountColumn(_parameter)\" >" );
537
+ sql .append ("COUNT(${countColumn})" );
538
+ sql .append ("</when>" );
539
+ sql .append ("<otherwise>" );
540
+ sql .append ("COUNT(0)" );
541
+ sql .append ("</otherwise>" );
542
+ sql .append ("</choose>" );
543
+ //不支持指定列的时候查询全部列
544
+ sql .append ("<if test=\" @tk.mybatis.mapper.util.OGNL@hasNoSelectColumns(_parameter)\" >" );
545
+ sql .append (getAllColumns (entityClass ));
546
+ sql .append ("</if>" );
547
+ return sql .toString ();
548
+ }
549
+
528
550
/**
529
551
* example查询中的orderBy条件,会判断默认orderBy
530
552
*
Original file line number Diff line number Diff line change @@ -70,6 +70,20 @@ public static boolean hasSelectColumns(Object parameter) {
70
70
return false ;
71
71
}
72
72
73
+ /**
74
+ * 是否包含自定义 Count 列
75
+ *
76
+ * @param parameter
77
+ * @return
78
+ */
79
+ public static boolean hasCountColumn (Object parameter ) {
80
+ if (parameter != null && parameter instanceof Example ) {
81
+ Example example = (Example ) parameter ;
82
+ return StringUtil .isNotEmpty (example .getCountColumn ());
83
+ }
84
+ return false ;
85
+ }
86
+
73
87
/**
74
88
* 是否包含 forUpdate
75
89
*
Original file line number Diff line number Diff line change 9
9
* 增加参数 ` simpleTypes ` ,默认的简单类型在 ` SimpleTypeUtil ` 中,使用该参数可以增加额外的简单类型,通过逗号隔开的全限定类名添加
10
10
* 所有 ` RuntimeException ` 异常改为 ` tk.mybatis.mapper.MapperException ` 异常
11
11
12
+ * 增加配置查询时的分隔符
13
+
12
14
##3 .3.9 - 2016-09-04
13
15
14
16
* 增加` selectByIds ` 和` deleteByIds ` ,用法见通用Mapper接口大全
You can’t perform that action at this time.
0 commit comments