Skip to content

Commit 72e1dc0

Browse files
committed
尝试增加查询列
1 parent d324785 commit 72e1dc0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import org.apache.ibatis.reflection.SystemMetaObject;
2929
import tk.mybatis.mapper.mapperhelper.EntityHelper;
3030

31-
import java.util.HashMap;
32-
import java.util.LinkedList;
33-
import java.util.List;
34-
import java.util.Map;
31+
import java.util.*;
3532

3633
/**
3734
* 通用的Example查询对象
@@ -45,6 +42,8 @@ public class Example {
4542

4643
protected boolean exists;
4744

45+
protected Set<String> selectColumns;
46+
4847
protected List<Criteria> oredCriteria;
4948

5049
protected Class<?> entityClass;
@@ -91,6 +90,24 @@ public void setOrderByClause(String orderByClause) {
9190
this.orderByClause = orderByClause;
9291
}
9392

93+
public Set<String> getSelectColumns() {
94+
return selectColumns;
95+
}
96+
97+
public Example selectProperties(String... properties) {
98+
if (properties != null && properties.length > 0) {
99+
if (this.selectColumns == null) {
100+
this.selectColumns = new LinkedHashSet<String>();
101+
}
102+
for (String property : properties) {
103+
if (propertyMap.containsKey(property)) {
104+
this.selectColumns.add(property);
105+
}
106+
}
107+
}
108+
return this;
109+
}
110+
94111
public boolean isDistinct() {
95112
return distinct;
96113
}

src/main/java/tk/mybatis/mapper/provider/MapperProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ public SqlNode selectByExample(MappedStatement ms) {
442442
sqlNodes.add(new StaticTextSqlNode("SELECT"));
443443
IfSqlNode distinctSqlNode = new IfSqlNode(new StaticTextSqlNode("DISTINCT"), "distinct");
444444
sqlNodes.add(distinctSqlNode);
445+
//TODO 增加Example中指定查询列的功能
445446
sqlNodes.add(new StaticTextSqlNode(EntityHelper.getSelectColumns(entityClass) + " FROM " + tableName(entityClass)));
446447
IfSqlNode ifNullSqlNode = new IfSqlNode(exampleWhereClause(ms.getConfiguration()), "_parameter != null");
447448
sqlNodes.add(ifNullSqlNode);

0 commit comments

Comments
 (0)