From f559c2e349e4df5fbdcef79cfac7d1e196cd4007 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 28 Dec 2018 22:47:47 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/mp/support/Condition.java | 3 +- .../springblade/core/mp/support/Query.java | 4 +- .../core/tool/utils/StringUtil.java | 40 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java index 5612408..1baddf2 100644 --- a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java +++ b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java @@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; import java.util.Map; @@ -70,7 +71,7 @@ public class Condition { if (Func.isNotEmpty(query)) { query.forEach((k, v) -> { if (Func.isNotEmpty(v)) { - qw.like(k, v); + qw.like(StringUtil.humpToUnderline(k), v); } }); } diff --git a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Query.java b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Query.java index 973fdef..fe162bd 100644 --- a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Query.java +++ b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Query.java @@ -45,13 +45,13 @@ public class Query { /** * 排序的字段名 */ - @ApiModelProperty(value = "升序字段") + @ApiModelProperty(hidden = true) private String ascs; /** * 排序方式 */ - @ApiModelProperty(value = "降序字段") + @ApiModelProperty(hidden = true) private String descs; } diff --git a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/StringUtil.java b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/StringUtil.java index 59b27fb..59e6920 100644 --- a/blade-core-tool/src/main/java/org/springblade/core/tool/utils/StringUtil.java +++ b/blade-core-tool/src/main/java/org/springblade/core/tool/utils/StringUtil.java @@ -199,7 +199,7 @@ public class StringUtil extends org.springframework.util.StringUtils { return txt.replaceAll("[  `·•�\\f\\t\\v\\s]", ""); } - + private static final String S_INT = "0123456789"; private static final String S_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; private static final String S_ALL = S_INT + S_STR; @@ -1338,6 +1338,44 @@ public class StringUtil extends org.springframework.util.StringUtils { return count; } + /** + * 下划线转驼峰 + * + * @param para + * @return + */ + public static String underlineToHump(String para) { + StringBuilder result = new StringBuilder(); + String[] a = para.split("_"); + for (String s : a) { + if (result.length() == 0) { + result.append(s.toLowerCase()); + } else { + result.append(s.substring(0, 1).toUpperCase()); + result.append(s.substring(1).toLowerCase()); + } + } + return result.toString(); + } + + /** + * 驼峰转下划线 + * + * @param para + * @return + */ + public static String humpToUnderline(String para) { + StringBuilder sb = new StringBuilder(para); + int temp = 0; + for (int i = 0; i < para.length(); i++) { + if (Character.isUpperCase(para.charAt(i))) { + sb.insert(i + temp, "_"); + temp += 1; + } + } + return sb.toString().toLowerCase(); + } + }