优化代码

This commit is contained in:
smallchill 2018-12-28 22:47:47 +08:00
parent 61f53ef39f
commit f559c2e349
3 changed files with 43 additions and 4 deletions

View File

@ -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);
}
});
}

View File

@ -45,13 +45,13 @@ public class Query {
/**
* 排序的字段名
*/
@ApiModelProperty(value = "升序字段")
@ApiModelProperty(hidden = true)
private String ascs;
/**
* 排序方式
*/
@ApiModelProperty(value = "降序字段")
@ApiModelProperty(hidden = true)
private String descs;
}

View File

@ -199,7 +199,7 @@ public class StringUtil extends org.springframework.util.StringUtils {
return txt.replaceAll("[  `·•<C2B7>\\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();
}
}