File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
src/main/java/tk/mybatis/mapper Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 28
28
import org .apache .ibatis .reflection .SystemMetaObject ;
29
29
import tk .mybatis .mapper .mapperhelper .EntityHelper ;
30
30
31
- import java .util .HashMap ;
32
- import java .util .LinkedList ;
33
- import java .util .List ;
34
- import java .util .Map ;
31
+ import java .util .*;
35
32
36
33
/**
37
34
* 通用的Example查询对象
@@ -45,6 +42,8 @@ public class Example {
45
42
46
43
protected boolean exists ;
47
44
45
+ protected Set <String > selectColumns ;
46
+
48
47
protected List <Criteria > oredCriteria ;
49
48
50
49
protected Class <?> entityClass ;
@@ -91,6 +90,24 @@ public void setOrderByClause(String orderByClause) {
91
90
this .orderByClause = orderByClause ;
92
91
}
93
92
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
+
94
111
public boolean isDistinct () {
95
112
return distinct ;
96
113
}
Original file line number Diff line number Diff line change @@ -442,6 +442,7 @@ public SqlNode selectByExample(MappedStatement ms) {
442
442
sqlNodes .add (new StaticTextSqlNode ("SELECT" ));
443
443
IfSqlNode distinctSqlNode = new IfSqlNode (new StaticTextSqlNode ("DISTINCT" ), "distinct" );
444
444
sqlNodes .add (distinctSqlNode );
445
+ //TODO 增加Example中指定查询列的功能
445
446
sqlNodes .add (new StaticTextSqlNode (EntityHelper .getSelectColumns (entityClass ) + " FROM " + tableName (entityClass )));
446
447
IfSqlNode ifNullSqlNode = new IfSqlNode (exampleWhereClause (ms .getConfiguration ()), "_parameter != null" );
447
448
sqlNodes .add (ifNullSqlNode );
You can’t perform that action at this time.
0 commit comments