Skip to content

Commit 30d07ea

Browse files
committed
由于typeHandlers全局配置导致没有测试出Wrapper的问题,修复Wrapper中TypeHandler的支持
1 parent a904f53 commit 30d07ea

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public ExampleWrapper<T, I> isNull(boolean useCondition, Fn<T, Object> fn) {
265265
* @param fn 字段对应的 get 方法引用
266266
*/
267267
public ExampleWrapper<T, I> isNull(Fn<T, Object> fn) {
268-
this.current.addCriterion(fn.toColumn() + " IS NULL");
268+
this.current.andIsNull(fn);
269269
return this;
270270
}
271271

@@ -285,7 +285,7 @@ public ExampleWrapper<T, I> isNotNull(boolean useCondition, Fn<T, Object> fn) {
285285
* @param fn 字段对应的 get 方法引用
286286
*/
287287
public ExampleWrapper<T, I> isNotNull(Fn<T, Object> fn) {
288-
this.current.addCriterion(fn.toColumn() + " IS NOT NULL");
288+
this.current.andIsNotNull(fn);
289289
return this;
290290
}
291291

@@ -318,7 +318,7 @@ public ExampleWrapper<T, I> eq(boolean useCondition, Fn<T, Object> fn, Supplier<
318318
* @param value 值
319319
*/
320320
public ExampleWrapper<T, I> eq(Fn<T, Object> fn, Object value) {
321-
this.current.addCriterion(fn.toColumn() + " =", value);
321+
this.current.andEqualTo(fn, value);
322322
return this;
323323
}
324324

@@ -351,7 +351,7 @@ public ExampleWrapper<T, I> ne(boolean useCondition, Fn<T, Object> fn, Object va
351351
* @param value 值
352352
*/
353353
public ExampleWrapper<T, I> ne(Fn<T, Object> fn, Object value) {
354-
this.current.addCriterion(fn.toColumn() + " <>", value);
354+
this.current.andNotEqualTo(fn, value);
355355
return this;
356356
}
357357

@@ -384,7 +384,7 @@ public ExampleWrapper<T, I> gt(boolean useCondition, Fn<T, Object> fn, Object va
384384
* @param value 值
385385
*/
386386
public ExampleWrapper<T, I> gt(Fn<T, Object> fn, Object value) {
387-
this.current.addCriterion(fn.toColumn() + " >", value);
387+
this.current.andGreaterThan(fn, value);
388388
return this;
389389
}
390390

@@ -417,7 +417,7 @@ public ExampleWrapper<T, I> ge(boolean useCondition, Fn<T, Object> fn, Object va
417417
* @param value 值
418418
*/
419419
public ExampleWrapper<T, I> ge(Fn<T, Object> fn, Object value) {
420-
this.current.addCriterion(fn.toColumn() + " >=", value);
420+
this.current.andGreaterThanOrEqualTo(fn, value);
421421
return this;
422422
}
423423

@@ -449,7 +449,7 @@ public ExampleWrapper<T, I> lt(boolean useCondition, Fn<T, Object> fn, Object va
449449
* @param value 值
450450
*/
451451
public ExampleWrapper<T, I> lt(Fn<T, Object> fn, Object value) {
452-
this.current.addCriterion(fn.toColumn() + " <", value);
452+
this.current.andLessThan(fn, value);
453453
return this;
454454
}
455455

@@ -482,7 +482,7 @@ public ExampleWrapper<T, I> le(boolean useCondition, Fn<T, Object> fn, Supplier<
482482
* @param value 值
483483
*/
484484
public ExampleWrapper<T, I> le(Fn<T, Object> fn, Object value) {
485-
this.current.addCriterion(fn.toColumn() + " <=", value);
485+
this.current.andLessThanOrEqualTo(fn, value);
486486
return this;
487487
}
488488

@@ -518,7 +518,7 @@ public ExampleWrapper<T, I> in(boolean useCondition, Fn<T, Object> fn, Supplier<
518518
*/
519519
@SuppressWarnings("rawtypes")
520520
public ExampleWrapper<T, I> in(Fn<T, Object> fn, Iterable values) {
521-
this.current.addCriterion(fn.toColumn() + " IN", values);
521+
this.current.andIn(fn, values);
522522
return this;
523523
}
524524

@@ -554,7 +554,7 @@ public ExampleWrapper<T, I> notIn(boolean useCondition, Fn<T, Object> fn, Suppli
554554
*/
555555
@SuppressWarnings("rawtypes")
556556
public ExampleWrapper<T, I> notIn(Fn<T, Object> fn, Iterable values) {
557-
this.current.addCriterion(fn.toColumn() + " NOT IN", values);
557+
this.current.andNotIn(fn, values);
558558
return this;
559559
}
560560

@@ -590,7 +590,7 @@ public ExampleWrapper<T, I> between(boolean useCondition, Fn<T, Object> fn, Supp
590590
* @param value2 值2
591591
*/
592592
public ExampleWrapper<T, I> between(Fn<T, Object> fn, Object value1, Object value2) {
593-
this.current.addCriterion(fn.toColumn() + " BETWEEN", value1, value2);
593+
this.current.andBetween(fn, value1, value2);
594594
return this;
595595
}
596596

@@ -626,7 +626,7 @@ public ExampleWrapper<T, I> notBetween(boolean useCondition, Fn<T, Object> fn, S
626626
* @param value2 值2
627627
*/
628628
public ExampleWrapper<T, I> notBetween(Fn<T, Object> fn, Object value1, Object value2) {
629-
this.current.addCriterion(fn.toColumn() + " NOT BETWEEN", value1, value2);
629+
this.current.andNotBetween(fn, value1, value2);
630630
return this;
631631
}
632632

@@ -736,7 +736,7 @@ public ExampleWrapper<T, I> endsWith(Fn<T, Object> fn, String value) {
736736
* @param fn 字段对应的 get 方法引用
737737
* @param value 值,需要指定 '%'(多个), '_'(单个) 模糊匹配
738738
*/
739-
public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, String value) {
739+
public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, Object value) {
740740
return useCondition ? like(fn, value) : this;
741741
}
742742

@@ -747,7 +747,7 @@ public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, String
747747
* @param fn 字段对应的 get 方法引用
748748
* @param supplier 值构造函数,需要指定 '%'(多个), '_'(单个) 模糊匹配
749749
*/
750-
public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
750+
public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
751751
return useCondition ? like(fn, supplier.get()) : this;
752752
}
753753

@@ -757,8 +757,8 @@ public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, Supplie
757757
* @param fn 字段对应的 get 方法引用
758758
* @param value 值,需要指定 '%'(多个), '_'(单个) 模糊匹配
759759
*/
760-
public ExampleWrapper<T, I> like(Fn<T, Object> fn, String value) {
761-
this.current.addCriterion(fn.toColumn() + " LIKE", value);
760+
public ExampleWrapper<T, I> like(Fn<T, Object> fn, Object value) {
761+
this.current.andLike(fn, value);
762762
return this;
763763
}
764764

@@ -769,7 +769,7 @@ public ExampleWrapper<T, I> like(Fn<T, Object> fn, String value) {
769769
* @param fn 字段对应的 get 方法引用
770770
* @param value 值,需要指定 % 模糊匹配
771771
*/
772-
public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, String value) {
772+
public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Object value) {
773773
return useCondition ? notLike(fn, value) : this;
774774
}
775775

@@ -780,7 +780,7 @@ public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Stri
780780
* @param fn 字段对应的 get 方法引用
781781
* @param supplier 值构造函数,需要指定 % 模糊匹配
782782
*/
783-
public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
783+
public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
784784
return useCondition ? notLike(fn, supplier.get()) : this;
785785
}
786786

@@ -790,8 +790,8 @@ public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Supp
790790
* @param fn 字段对应的 get 方法引用
791791
* @param value 值,需要指定 % 模糊匹配
792792
*/
793-
public ExampleWrapper<T, I> notLike(Fn<T, Object> fn, String value) {
794-
this.current.addCriterion(fn.toColumn() + " NOT LIKE", value);
793+
public ExampleWrapper<T, I> notLike(Fn<T, Object> fn, Object value) {
794+
this.current.andNotLike(fn, value);
795795
return this;
796796
}
797797

mapper/src/test/java/io/mybatis/mapper/UserAutoBaseMapperTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void testUpdateByExampleWrapperSetValues() {
5454
.set(UserAuto::getAddress, new UserAuto.Address("河北省", "秦皇岛市"))
5555
.eq(UserAuto::getId, 1L).update();
5656
Assert.assertEquals(1, update);
57+
58+
int delete = userAutoMapper.wrapper().eq(UserAuto::getAddress, new UserAuto.Address("河北省", "秦皇岛市")).delete();
59+
Assert.assertEquals(1, delete);
5760
sqlSession.rollback();
5861
} finally {
5962
//不要忘记关闭sqlSession

mapper/src/test/resources/mybatis-config.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
<package name="io.mybatis.simple.model"/>
3131
</typeAliases>
3232

33-
<typeHandlers>
34-
<typeHandler handler="io.mybatis.mapper.model.UserAuto$AddressTypeHandler"
35-
javaType="io.mybatis.mapper.model.UserAuto$Address"/>
36-
</typeHandlers>
37-
3833
<environments default="development">
3934
<environment id="development">
4035
<transactionManager type="JDBC">

0 commit comments

Comments
 (0)