Skip to content

Commit

Permalink
简化 Example 中的 variables 方法
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed May 20, 2024
1 parent 816180d commit 60d3813
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions mapper/src/main/java/io/mybatis/mapper/example/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -1382,13 +1382,9 @@ protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}

public String variables(String prefix, String field) {
public String variables(String field) {
StringBuilder variables = new StringBuilder();
variables.append("#{");
if(prefix != null && !prefix.isEmpty()) {
variables.append(prefix).append(".");
}
variables.append(field);
variables.append("#{").append(field);
if (typeHandler != null && !typeHandler.isEmpty()) {
variables.append(",typeHandler=").append(typeHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ExampleProvider {
" ${setValue.condition},\n" +
" </when>\n" +
" <when test=\"setValue.singleValue\">\n" +
" ${setValue.condition} = ${setValue.variables('setValue', 'value')},\n" +
" ${setValue.condition} = ${setValue.variables('setValue.value')},\n" +
" </when>\n" +
" </choose>\n" +
" </foreach>\n" +
Expand All @@ -48,17 +48,17 @@ public class ExampleProvider {
" AND ${criterion.condition}\n" +
" </when>\n" +
" <when test=\"criterion.singleValue\">\n" +
" AND ${criterion.condition} ${criterion.variables('criterion', 'value')}\n" +
" AND ${criterion.condition} ${criterion.variables('criterion.value')}\n" +
" </when>\n" +
" <when test=\"criterion.betweenValue\">\n" +
" AND ${criterion.condition} ${criterion.variables('criterion', 'value')} AND\n" +
" ${criterion.variables('criterion', 'secondValue')}\n" +
" AND ${criterion.condition} ${criterion.variables('criterion.value')} AND\n" +
" ${criterion.variables('criterion.secondValue')}\n" +
" </when>\n" +
" <when test=\"criterion.listValue\">\n" +
" AND ${criterion.condition}\n" +
" <foreach close=\")\" collection=\"criterion.value\" item=\"listItem\"\n" +
" open=\"(\" separator=\",\">\n" +
" ${criterion.variables(null, 'listItem')}\n" +
" ${criterion.variables('listItem')}\n" +
" </foreach>\n" +
" </when>\n";

Expand Down

0 comments on commit 60d3813

Please sign in to comment.