Commit 6a0612bf authored by 胡小根's avatar 胡小根

fix query condition

parent a4ed4fe1
...@@ -3,6 +3,7 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils; ...@@ -3,6 +3,7 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.haomostudio.SeekTruthBackend.service.HmUtils.Tools;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.*; import java.util.*;
...@@ -39,10 +40,17 @@ public class MybatisExampleHelper { ...@@ -39,10 +40,17 @@ public class MybatisExampleHelper {
* @return * @return
*/ */
public static String getFilterFuncName(String column, String condition){ public static String getFilterFuncName(String column, String condition){
return "and" if(column.contains("_")){
+ CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, column) return "and"
+ CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, condition); + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, column)
}; + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, condition);
}
else{
return "and"
+ column.substring(0,1).toUpperCase() + column.substring(1)
+ CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, condition);
}
}
public static Method getMethod(Object obj, String methodName){ public static Method getMethod(Object obj, String methodName){
for(Method m: obj.getClass().getDeclaredMethods()){ for(Method m: obj.getClass().getDeclaredMethods()){
...@@ -78,20 +86,45 @@ public class MybatisExampleHelper { ...@@ -78,20 +86,45 @@ public class MybatisExampleHelper {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
break; break;
// 需要考虑时间和Number等字段
case "between": case "between":
case "notBetween": case "notBetween":
try{ try{
m.invoke(exampleObjCriteria, if(m.getParameterTypes()[0].getName().contains("Date")){
((List<String>) value).get(0), m.invoke(exampleObjCriteria,
((List<String>) value).get(1)); Tools.convertStringToDate(((List<String>) value).get(0), "yyyy-MM-dd HH:mm:ss"),
Tools.convertStringToDate(((List<String>) value).get(1), "yyyy-MM-dd HH:mm:ss"));
} else if(m.getParameterTypes()[0].getName().contains("Long")){
m.invoke(exampleObjCriteria,
((List<Long>) value).get(0),
((List<Long>) value).get(1));
} else{
m.invoke(exampleObjCriteria,
((List<Integer>) value).get(0),
((List<Integer>) value).get(1));
}
} }
catch (ReflectiveOperationException e){ catch (ReflectiveOperationException e){
throw new RuntimeException(e); throw new RuntimeException(e);
} }
break; break;
default: default:
try{ try{
m.invoke(exampleObjCriteria, value); if(m.getParameterTypes()[0].getName().contains("Date")){
m.invoke(exampleObjCriteria,
Tools.convertStringToDate((String)value, "yyyy-MM-dd HH:mm:ss"));
} else if(m.getParameterTypes()[0].getName().contains("Long")){
m.invoke(exampleObjCriteria, Long.valueOf((String)value));
} else if(m.getParameterTypes()[0].getName().contains("Integer")){
m.invoke(exampleObjCriteria, Integer.valueOf((String)value));
} else if(m.getParameterTypes()[0].getName().contains("int")){
m.invoke(exampleObjCriteria, (int)value);
} else {
m.invoke(exampleObjCriteria, value);
}
} }
catch (ReflectiveOperationException e){ catch (ReflectiveOperationException e){
throw new RuntimeException(e); throw new RuntimeException(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment