Skip to content

Commit c521f00

Browse files
committed
更新群链接
1 parent 39edeeb commit c521f00

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ MyBatis 工具网站:[http://mybatis.tk](http://www.mybatis.tk)
122122

123123
作者邮箱: abel533@gmail.com
124124

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>
126126

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>
128128

129129
推荐使用Mybatis分页插件:[PageHelper分页插件](https://github.com/pagehelper/Mybatis-PageHelper)

src/main/java/tk/mybatis/mapper/entity/Example.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class Example implements IDynamicTableName {
5151

5252
protected Set<String> selectColumns;
5353

54+
protected String countColumn;
55+
5456
protected List<Criteria> oredCriteria;
5557

5658
protected Class<?> entityClass;
@@ -194,6 +196,21 @@ public Example selectProperties(String... properties) {
194196
return this;
195197
}
196198

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+
197214
public boolean isDistinct() {
198215
return distinct;
199216
}

src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,28 @@ public static String exampleSelectColumns(Class<?> entityClass) {
525525
return sql.toString();
526526
}
527527

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+
528550
/**
529551
* example查询中的orderBy条件,会判断默认orderBy
530552
*

src/main/java/tk/mybatis/mapper/util/OGNL.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ public static boolean hasSelectColumns(Object parameter) {
7070
return false;
7171
}
7272

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+
7387
/**
7488
* 是否包含 forUpdate
7589
*

wiki/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 增加参数 `simpleTypes`,默认的简单类型在 `SimpleTypeUtil` 中,使用该参数可以增加额外的简单类型,通过逗号隔开的全限定类名添加
1010
* 所有 `RuntimeException` 异常改为 `tk.mybatis.mapper.MapperException` 异常
1111

12+
* 增加配置查询时的分隔符
13+
1214
##3.3.9 - 2016-09-04
1315

1416
* 增加`selectByIds``deleteByIds`,用法见通用Mapper接口大全

0 commit comments

Comments
 (0)