Skip to content

Commit 8106576

Browse files
committed
可以select以后直接order by
1 parent eaa7f75 commit 8106576

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/main/java/com/codingapi/simplemybatis/query/ConditionParameter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public ConditionParameter(Map<String,Object> map, String sql) {
3636
public ConditionParameter(Object val, String sql) {
3737
this.map = new HashMap<>();
3838
String key = new PatternMatcherHelper(PatternMatcherHelper.BRACE_MATCHER).matcher(sql);
39-
map.put(key,val);
39+
if(key!=null) {
40+
map.put(key, val);
41+
}
4042
this.sql = sql;
4143
}
4244

src/main/java/com/codingapi/simplemybatis/query/QueryBuilder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,10 @@ public Splice condition(String conditionSql,String paramKey, Object paramVal) {
3838

3939

4040
public Splice condition(String conditionSql,Map<String,Object> map) {
41-
if(map!=null&&map.size()>0) {
42-
conditions.add(new ConditionParameter(map, conditionSql));
43-
}else{
44-
splice.remove();
45-
}
41+
conditions.add(new ConditionParameter(map, conditionSql));
4642
return splice;
4743
}
4844

49-
5045
public Splice condition(String conditionSql,Object paramVal) {
5146
if(paramVal!=null) {
5247
conditions.add(new ConditionParameter(paramVal, conditionSql));

src/test/java/com/codingapi/simplemybatis/query/QueryTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ void queryView() throws InvocationTargetException, IllegalAccessException {
6363
}
6464

6565

66+
@Test
67+
void queryNumberKey() throws InvocationTargetException, IllegalAccessException {
68+
Query query = QueryBuilder.Build()
69+
.select("select * from t_demo d join t_test t on d.id = t.demo_id ")
70+
.where()
71+
.condition("d.order = #{?1} or d.order = #{?2} or d.order = #{?3} or d.order = #{?4} ",1,2,3,4)
72+
.builder();
73+
SqlBuilder sqlBuilder = new SqlBuilder(query.getSelect(),null,query);
74+
String sql = sqlBuilder.getSql();
75+
System.out.println(sql);
76+
}
77+
6678
@Test
6779
void queryOrderBy() throws InvocationTargetException, IllegalAccessException {
6880
Query query = QueryBuilder.Build()
@@ -74,6 +86,18 @@ void queryOrderBy() throws InvocationTargetException, IllegalAccessException {
7486
System.out.println(sql);
7587
}
7688

89+
@Test
90+
void queryLikeKey() throws InvocationTargetException, IllegalAccessException {
91+
Query query = QueryBuilder.Build()
92+
.select("select * from t_demo d join t_test t on d.id = t.demo_id ")
93+
.where()
94+
.condition("d.name = #{name} and d.name = '123'",new HashMap<>())
95+
.builder();
96+
SqlBuilder sqlBuilder = new SqlBuilder(query.getSelect(),null,query);
97+
String sql = sqlBuilder.getSql();
98+
System.out.println(sql);
99+
}
100+
77101
@Test
78102
void queryNotNullView() throws InvocationTargetException, IllegalAccessException {
79103
Object object = Arrays.asList(1,2,3,4,5,6,7,8,9,10);

0 commit comments

Comments
 (0)