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

fix query condition

parent a4ed4fe1
......@@ -3,6 +3,7 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.CaseFormat;
import com.haomostudio.SeekTruthBackend.service.HmUtils.Tools;
import java.lang.reflect.Method;
import java.util.*;
......@@ -39,10 +40,17 @@ public class MybatisExampleHelper {
* @return
*/
public static String getFilterFuncName(String column, String condition){
if(column.contains("_")){
return "and"
+ 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){
for(Method m: obj.getClass().getDeclaredMethods()){
......@@ -78,21 +86,46 @@ public class MybatisExampleHelper {
throw new RuntimeException(e);
}
break;
// 需要考虑时间和Number等字段
case "between":
case "notBetween":
try{
if(m.getParameterTypes()[0].getName().contains("Date")){
m.invoke(exampleObjCriteria,
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<String>) value).get(0),
((List<String>) value).get(1));
((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){
throw new RuntimeException(e);
}
break;
default:
try{
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){
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