Skip to content

Commit d4b244c

Browse files
committed
Merge branch 'develop'
2 parents 5917db1 + c975b22 commit d4b244c

File tree

9 files changed

+55
-20
lines changed

9 files changed

+55
-20
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Country代码:
9292
<dependency>
9393
<groupId>tk.mybatis</groupId>
9494
<artifactId>mapper</artifactId>
95-
<version>3.3.3</version>
95+
<version>3.3.4</version>
9696
</dependency>
9797
```
9898

@@ -108,7 +108,13 @@ http://repo1.maven.org/maven2/javax/persistence/persistence-api/1.0/
108108

109109
##[更新日志](http://git.oschina.net/free/Mapper/blob/master/wiki/Changelog.md)
110110

111-
##最新版本3.3.3 - 2015-12-30
111+
##最新版本3.3.4 - 2016-01-05
112+
113+
* 解决insertList的bug#86
114+
* `Example`构造方法增加`notNull`参数,默认`false`,允许值为`null`,值为`null`的时候不加入到条件中。
115+
* `seqFormat`格式化参数增加第四个可配置值`TableName`,该属性的具体含义请参考[如何集成通用Mapper](http://git.oschina.net/free/Mapper/blob/master/wiki/mapper3/2.Integration.md)中的参数介绍
116+
117+
###3.3.3 - 2015-12-30
112118

113119
- 解决OGNL中的and,or大写导致的错误
114120
- 解决SpecialProvider不支持insertable的bug#77

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<groupId>tk.mybatis</groupId>
3030
<artifactId>mapper</artifactId>
31-
<version>3.3.3</version>
31+
<version>3.3.4</version>
3232
<packaging>jar</packaging>
3333

3434
<name>mapper</name>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ public Condition(Class<?> entityClass) {
3838
public Condition(Class<?> entityClass, boolean exists) {
3939
super(entityClass, exists);
4040
}
41+
42+
public Condition(Class<?> entityClass, boolean exists, boolean notNull) {
43+
super(entityClass, exists, notNull);
44+
}
4145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public String getSeqFormat() {
146146

147147
/**
148148
* 序列的获取规则,使用{num}格式化参数,默认值为{0}.nextval,针对Oracle
149-
* <br>可选参数一共3个,对应0,1,2,分别为SequenceName,ColumnName, PropertyName
149+
* <br>可选参数一共3个,对应0,1,2,3分别为SequenceName,ColumnName, PropertyName,TableName
150150
*
151151
* @param seqFormat
152152
*/

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class Example {
4343

4444
protected boolean exists;
4545

46+
protected boolean notNull;
47+
4648
protected Set<String> selectColumns;
4749

4850
protected List<Criteria> oredCriteria;
@@ -63,13 +65,25 @@ public Example(Class<?> entityClass) {
6365
}
6466

6567
/**
66-
* 带exists参数的构造方法
68+
* 带exists参数的构造方法,默认notNull为false,允许为空
6769
*
6870
* @param entityClass
6971
* @param exists - true时,如果字段不存在就抛出异常,false时,如果不存在就不使用该字段的条件
7072
*/
7173
public Example(Class<?> entityClass, boolean exists) {
74+
this(entityClass, exists, false);
75+
}
76+
77+
/**
78+
* 带exists参数的构造方法
79+
*
80+
* @param entityClass
81+
* @param exists - true时,如果字段不存在就抛出异常,false时,如果不存在就不使用该字段的条件
82+
* @param notNull - true时,如果值为空,就会抛出异常,false时,如果为空就不使用该字段的条件
83+
*/
84+
public Example(Class<?> entityClass, boolean exists, boolean notNull) {
7285
this.exists = exists;
86+
this.notNull = notNull;
7387
oredCriteria = new ArrayList<Criteria>();
7488
this.entityClass = entityClass;
7589
table = EntityHelper.getEntityTable(entityClass);
@@ -146,7 +160,7 @@ public Criteria createCriteria() {
146160
}
147161

148162
protected Criteria createCriteriaInternal() {
149-
Criteria criteria = new Criteria(propertyMap, exists);
163+
Criteria criteria = new Criteria(propertyMap, exists, notNull);
150164
return criteria;
151165
}
152166

@@ -160,16 +174,15 @@ protected abstract static class GeneratedCriteria {
160174
protected List<Criterion> criteria;
161175
//字段是否必须存在
162176
protected boolean exists;
177+
//值是否不能为空
178+
protected boolean notNull;
163179
//属性和列对应
164180
protected Map<String, EntityColumn> propertyMap;
165181

166-
protected GeneratedCriteria(Map<String, EntityColumn> propertyMap) {
167-
this(propertyMap, true);
168-
}
169-
170-
protected GeneratedCriteria(Map<String, EntityColumn> propertyMap, boolean exists) {
182+
protected GeneratedCriteria(Map<String, EntityColumn> propertyMap, boolean exists, boolean notNull) {
171183
super();
172184
this.exists = exists;
185+
this.notNull = notNull;
173186
criteria = new ArrayList<Criterion>();
174187
this.propertyMap = propertyMap;
175188
}
@@ -218,7 +231,11 @@ protected void addCriterion(String condition) {
218231

219232
protected void addCriterion(String condition, Object value, String property) {
220233
if (value == null) {
221-
throw new RuntimeException("Value for " + property + " cannot be null");
234+
if (notNull) {
235+
throw new RuntimeException("Value for " + property + " cannot be null");
236+
} else {
237+
return;
238+
}
222239
}
223240
if (property == null) {
224241
return;
@@ -228,7 +245,11 @@ protected void addCriterion(String condition, Object value, String property) {
228245

229246
protected void addCriterion(String condition, Object value1, Object value2, String property) {
230247
if (value1 == null || value2 == null) {
231-
throw new RuntimeException("Between values for " + property + " cannot be null");
248+
if (notNull) {
249+
throw new RuntimeException("Between values for " + property + " cannot be null");
250+
} else {
251+
return;
252+
}
232253
}
233254
if (property == null) {
234255
return;
@@ -384,12 +405,9 @@ public Criteria andEqualTo(Object param) {
384405
}
385406

386407
public static class Criteria extends GeneratedCriteria {
387-
protected Criteria(Map<String, EntityColumn> propertyMap) {
388-
super(propertyMap);
389-
}
390408

391-
protected Criteria(Map<String, EntityColumn> propertyMap, boolean exists) {
392-
super(propertyMap, exists);
409+
protected Criteria(Map<String, EntityColumn> propertyMap, boolean exists, boolean notNull) {
410+
super(propertyMap, exists, notNull);
393411
}
394412
}
395413

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public void setSqlSource(MappedStatement ms) {
244244
mapperTemplate.setSqlSource(ms);
245245
}
246246
} catch (Exception e) {
247-
throw new RuntimeException("调用方法异常:" + e.getMessage());
247+
throw new RuntimeException(e);
248248
}
249249
}
250250

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String insertList(MappedStatement ms) {
5858
sql.append(SqlHelper.insertColumns(entityClass, true, false, false));
5959
sql.append(" VALUES ");
6060
sql.append("<foreach collection=\"list\" item=\"record\" separator=\",\" >");
61-
sql.append("<trim prefix=\"VALUES (\" suffix=\")\" suffixOverrides=\",\">");
61+
sql.append("<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">");
6262
//获取全部列
6363
Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
6464
//当某个列有主键策略时,不需要考虑他的属性是否为空,因为如果为空,一定会根据主键策略给他生成一个值

wiki/Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#更新日志
22

3+
##3.3.4 - 2016-01-05
4+
5+
* 解决insertList的bug#86
6+
* `Example`构造方法增加`notNull`参数,默认`false`,允许值为`null`,值为`null`的时候不加入到条件中。
7+
* `seqFormat`格式化参数增加第四个可配置值`TableName`
8+
39
##3.3.3 - 2015-12-30
410

511
- 解决OGNL中的and,or大写导致的错误

wiki/mapper3/2.Integration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ mapperHelper.processConfiguration(session.getConfiguration());
7878
* `ORDER``<selectKey>`中的`order`属性,可选值为`BEFORE``AFTER`
7979
* `catalog`:数据库的`catalog`,如果设置该值,查询的时候表名会带`catalog`设置的前缀
8080
* `schema`:同`catalog``catalog`优先级高于`schema`
81+
* `seqFormat`:序列的获取规则,使用{num}格式化参数,默认值为`{0}.nextval`,针对Oracle,可选参数一共4个,对应0,1,2,3分别为`SequenceName,ColumnName, PropertyName,TableName`
8182
* `notEmpty`:insert和update中,是否判断字符串类型`!=''`,少数方法会用到
8283
* `style`:实体和表转换时的规则,默认驼峰转下划线,可选值为`normal`用实体名和字段名;`camelhump`是默认值,驼峰转下划线;`uppercase`转换为大写;`lowercase`转换为小写
8384
* `enableMethodAnnotation`:可以控制是否支持方法上的JPA注解,默认`false`

0 commit comments

Comments
 (0)