diff --git a/mapper/src/main/java/io/mybatis/mapper/example/Example.java b/mapper/src/main/java/io/mybatis/mapper/example/Example.java index 84dcb3b..c7b28ea 100644 --- a/mapper/src/main/java/io/mybatis/mapper/example/Example.java +++ b/mapper/src/main/java/io/mybatis/mapper/example/Example.java @@ -476,7 +476,7 @@ public Example set(String setSql) { */ public Example set(Fn fn, Object value) { EntityColumn column = fn.toEntityColumn(); - this.setValues.add(new Criterion(column.column(), value, column.typeHandler())); + this.setValues.add(new Criterion(column.column(), value, column)); return this; } @@ -545,11 +545,11 @@ protected void addCriterion(String condition, Object value) { criteria.add(new Criterion(condition, value)); } - protected void addCriterion(String condition, Object value, Class typeHandler) { + protected void addCriterion(String condition, Object value, EntityColumn column) { if (value == null) { throw new RuntimeException("Value for " + condition + " cannot be null"); } - criteria.add(new Criterion(condition, value, typeHandler)); + criteria.add(new Criterion(condition, value, column)); } protected void addCriterion(String condition, Object value1, Object value2) { @@ -559,11 +559,11 @@ protected void addCriterion(String condition, Object value1, Object value2) { criteria.add(new Criterion(condition, value1, value2)); } - protected void addCriterion(String condition, Object value1, Object value2, Class typeHandler) { + protected void addCriterion(String condition, Object value1, Object value2, EntityColumn column) { if (value1 == null || value2 == null) { throw new RuntimeException("Between values for " + condition + " cannot be null"); } - criteria.add(new Criterion(condition, value1, value2, typeHandler)); + criteria.add(new Criterion(condition, value1, value2, column)); } public Criteria andIsNull(boolean useCondition, Fn fn) { @@ -590,7 +590,7 @@ public Criteria andEqualTo(boolean useCondition, Fn fn, Object val public Criteria andEqualTo(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " =", value, typehandler(fn)); + addCriterion(column(fn) + " =", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -601,7 +601,7 @@ public Criteria andNotEqualTo(boolean useCondition, Fn fn, Object public Criteria andNotEqualTo(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " <>", value, typehandler(fn)); + addCriterion(column(fn) + " <>", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -612,7 +612,7 @@ public Criteria andGreaterThan(boolean useCondition, Fn fn, Object public Criteria andGreaterThan(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " >", value, typehandler(fn)); + addCriterion(column(fn) + " >", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -623,7 +623,7 @@ public Criteria andGreaterThanOrEqualTo(boolean useCondition, Fn f public Criteria andGreaterThanOrEqualTo(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " >=", value, typehandler(fn)); + addCriterion(column(fn) + " >=", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -634,7 +634,7 @@ public Criteria andLessThan(boolean useCondition, Fn fn, Object va public Criteria andLessThan(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " <", value, typehandler(fn)); + addCriterion(column(fn) + " <", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -645,7 +645,7 @@ public Criteria andLessThanOrEqualTo(boolean useCondition, Fn fn, public Criteria andLessThanOrEqualTo(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " <=", value, typehandler(fn)); + addCriterion(column(fn) + " <=", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -657,7 +657,7 @@ public Criteria andIn(boolean useCondition, Fn fn, Iterable values @SuppressWarnings("rawtypes") public Criteria andIn(Fn fn, Iterable values) { if (useCriterion(values)) { - addCriterion(column(fn) + " IN", values, typehandler(fn)); + addCriterion(column(fn) + " IN", values, fn.toEntityColumn()); } return (Criteria) this; } @@ -669,7 +669,7 @@ public Criteria andNotIn(boolean useCondition, Fn fn, Iterable val @SuppressWarnings("rawtypes") public Criteria andNotIn(Fn fn, Iterable values) { if (useCriterion(values)) { - addCriterion(column(fn) + " NOT IN", values, typehandler(fn)); + addCriterion(column(fn) + " NOT IN", values, fn.toEntityColumn()); } return (Criteria) this; } @@ -680,7 +680,7 @@ public Criteria andBetween(boolean useCondition, Fn fn, Object val public Criteria andBetween(Fn fn, Object value1, Object value2) { if (useCriterion(value1) && useCriterion(value2)) { - addCriterion(column(fn) + " BETWEEN", value1, value2, typehandler(fn)); + addCriterion(column(fn) + " BETWEEN", value1, value2, fn.toEntityColumn()); } return (Criteria) this; } @@ -691,7 +691,7 @@ public Criteria andNotBetween(boolean useCondition, Fn fn, Object public Criteria andNotBetween(Fn fn, Object value1, Object value2) { if (useCriterion(value1) && useCriterion(value2)) { - addCriterion(column(fn) + " NOT BETWEEN", value1, value2, typehandler(fn)); + addCriterion(column(fn) + " NOT BETWEEN", value1, value2, fn.toEntityColumn()); } return (Criteria) this; } @@ -702,7 +702,7 @@ public Criteria andLike(boolean useCondition, Fn fn, Object value) public Criteria andLike(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " LIKE", value, typehandler(fn)); + addCriterion(column(fn) + " LIKE", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -713,7 +713,7 @@ public Criteria andNotLike(boolean useCondition, Fn fn, Object val public Criteria andNotLike(Fn fn, Object value) { if (useCriterion(value)) { - addCriterion(column(fn) + " NOT LIKE", value, typehandler(fn)); + addCriterion(column(fn) + " NOT LIKE", value, fn.toEntityColumn()); } return (Criteria) this; } @@ -1331,6 +1331,8 @@ public static class Criterion { private Object secondValue; + private String javaType; + private String typeHandler; private boolean noValue; @@ -1353,11 +1355,12 @@ protected Criterion(String condition) { this.noValue = true; } - protected Criterion(String condition, Object value, Class typeHandler) { + protected Criterion(String condition, Object value, EntityColumn column) { super(); this.condition = condition; this.value = value; - this.typeHandler = typeHandler != null ? typeHandler.getName() : null; + this.javaType = value != null ? column.javaType().getName() : null; + this.typeHandler = typeHandler != null ? column.typeHandler().getName() : null; if (value instanceof Collection) { if (condition != null) { this.listValue = true; @@ -1369,12 +1372,13 @@ protected Criterion(String condition, Object value, Class } } - protected Criterion(String condition, Object value, Object secondValue, Class typeHandler) { + protected Criterion(String condition, Object value, Object secondValue, EntityColumn column) { super(); this.condition = condition; this.value = value; this.secondValue = secondValue; - this.typeHandler = typeHandler != null ? typeHandler.getName() : null; + this.javaType = value != null ? column.javaType().getName() : null; + this.typeHandler = typeHandler != null ? column.typeHandler().getName() : null; this.betweenValue = true; } @@ -1385,6 +1389,9 @@ protected Criterion(String condition, Object value, Object secondValue) { public String variables(String field) { StringBuilder variables = new StringBuilder(); variables.append("#{").append(field); + if (javaType != null && !javaType.isEmpty()) { + variables.append(",javaType=").append(javaType); + } if (typeHandler != null && !typeHandler.isEmpty()) { variables.append(",typeHandler=").append(typeHandler); }