Skip to content

Commit 749c983

Browse files
committed
and
1 parent dc606c7 commit 749c983

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Country代码:
9292

9393
* 修复Mapper<T>接口中update操作会更新主键的bug
9494

95+
* 修复Mapper<T>接口中使用Example查询的时候,条件and前面缺少空格,导致在sqlserver中出错
96+
9597
* MBG插件增加caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true
9698

9799
###2.3.0 - 2015-04-05

src/main/java/com/github/abel533/mapperhelper/MapperTemplate.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,15 @@ protected void newSelectKeyMappedStatement(MappedStatement ms, EntityHelper.Enti
457457

458458
public IfSqlNode ExampleValidSqlNode(Configuration configuration) {
459459
List<SqlNode> whenSqlNodes = new ArrayList<SqlNode>();
460-
IfSqlNode noValueSqlNode = new IfSqlNode(new TextSqlNode("and ${criterion.condition}"), "criterion.noValue");
460+
IfSqlNode noValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition}"), "criterion.noValue");
461461
whenSqlNodes.add(noValueSqlNode);
462-
IfSqlNode singleValueSqlNode = new IfSqlNode(new TextSqlNode("and ${criterion.condition} #{criterion.value}"), "criterion.singleValue");
462+
IfSqlNode singleValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition} #{criterion.value}"), "criterion.singleValue");
463463
whenSqlNodes.add(singleValueSqlNode);
464-
IfSqlNode betweenValueSqlNode = new IfSqlNode(new TextSqlNode("and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}"), "criterion.betweenValue");
464+
IfSqlNode betweenValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}"), "criterion.betweenValue");
465465
whenSqlNodes.add(betweenValueSqlNode);
466466

467467
List<SqlNode> listValueContentSqlNodes = new ArrayList<SqlNode>();
468-
listValueContentSqlNodes.add(new TextSqlNode("and ${criterion.condition}"));
468+
listValueContentSqlNodes.add(new TextSqlNode(" and ${criterion.condition}"));
469469
ForEachSqlNode listValueForEachSqlNode = new ForEachSqlNode(configuration, new StaticTextSqlNode("#{listItem}"), "criterion.value", null, "listItem", "(", ")", ",");
470470
listValueContentSqlNodes.add(listValueForEachSqlNode);
471471
IfSqlNode listValueSqlNode = new IfSqlNode(new MixedSqlNode(listValueContentSqlNodes), "criterion.noValue");
@@ -487,7 +487,7 @@ public IfSqlNode ExampleValidSqlNode(Configuration configuration) {
487487
* @return
488488
*/
489489
public WhereSqlNode exampleWhereClause(Configuration configuration) {
490-
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(configuration, ExampleValidSqlNode(configuration), "oredCriteria", null, "criteria", null, null, "or");
490+
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(configuration, ExampleValidSqlNode(configuration), "oredCriteria", null, "criteria", null, null, " or ");
491491
WhereSqlNode whereSqlNode = new WhereSqlNode(configuration, forEachSqlNode);
492492
return whereSqlNode;
493493
}
@@ -500,7 +500,7 @@ public WhereSqlNode exampleWhereClause(Configuration configuration) {
500500
*/
501501
public WhereSqlNode updateByExampleWhereClause(Configuration configuration) {
502502
//和上面方法的区别就在"example.oredCriteria"
503-
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(configuration, ExampleValidSqlNode(configuration), "example.oredCriteria", null, "criteria", null, null, "or");
503+
ForEachSqlNode forEachSqlNode = new ForEachSqlNode(configuration, ExampleValidSqlNode(configuration), "example.oredCriteria", null, "criteria", null, null, " or ");
504504
WhereSqlNode whereSqlNode = new WhereSqlNode(configuration, forEachSqlNode);
505505
return whereSqlNode;
506506
}

src/test/java/com/github/abel533/test/example/TestSelectByExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ public void testSelectByExample() {
2222
try {
2323
CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
2424
Example example = new Example(Country.class);
25-
example.createCriteria().andGreaterThan("id", 100);
25+
example.createCriteria().andGreaterThan("id", 100).andLessThan("id",151);
26+
example.or().andLessThan("id",41);
2627
List<Country> countries = mapper.selectByExample(example);
2728
//查询总数
28-
Assert.assertEquals(83, countries.size());
29+
Assert.assertEquals(90, countries.size());
2930
} finally {
3031
sqlSession.close();
3132
}
@@ -39,7 +40,7 @@ public void testSelectByExample2() {
3940
Example example = new Example(Country.class);
4041
example.createCriteria().andLike("countryname", "A%");
4142
example.or().andGreaterThan("id", 100);
42-
example.setDistinct(true);
43+
example. setDistinct(true);
4344
List<Country> countries = mapper.selectByExample(example);
4445
//查询总数
4546
Assert.assertEquals(true, countries.size() > 83);

wiki/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* 修复Mapper<T>接口中update操作会更新主键的bug
88

9+
* 修复Mapper<T>接口中使用Example查询的时候,条件and前面缺少空格,导致在sqlserver中出错
10+
911
* MBG插件增加caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true
1012

1113
##2.3.0 - 2015-04-05

0 commit comments

Comments
 (0)