🎉 new mod
This commit is contained in:
parent
553fbc698e
commit
1fa96a66c8
21
src/main/java/utils/HandlePage.java
Normal file
21
src/main/java/utils/HandlePage.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fuhouyin
|
||||||
|
* @time 2023/2/1 15:07
|
||||||
|
*/
|
||||||
|
public class HandlePage {
|
||||||
|
|
||||||
|
/**分页 start = (page - 1) * size, end = page * size*/
|
||||||
|
private <T> List<T> handlePage(List<T> source, int start, int end){
|
||||||
|
int total = source.size();
|
||||||
|
// end = end > total ? total : end;
|
||||||
|
end = Math.min(end, total);
|
||||||
|
if (end <= start) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.subList(start,end);
|
||||||
|
}
|
||||||
|
}
|
94
src/main/java/utils/MethodGetAndSet.java
Normal file
94
src/main/java/utils/MethodGetAndSet.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package utils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fuhouyin
|
||||||
|
* @time 2023/2/1 15:10
|
||||||
|
*/
|
||||||
|
public class MethodGetAndSet {
|
||||||
|
|
||||||
|
/**根据属性,获取get方法*/
|
||||||
|
private Object getGetMethod(Object ob , String name)throws Exception{
|
||||||
|
Method[] m = ob.getClass().getMethods();
|
||||||
|
for(int i = 0;i < m.length;i++){
|
||||||
|
if(("get"+name).toLowerCase().equals(m[i].getName().toLowerCase())){
|
||||||
|
return m[i].invoke(ob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**根据属性,拿到set方法,并把值set到对象中*/
|
||||||
|
private void setValue(Object obj,Class<?> clazz,String filedName,Class<?> typeClass,Object value){
|
||||||
|
filedName = removeLine(filedName);
|
||||||
|
String methodName = "set" + filedName.substring(0,1).toUpperCase()+filedName.substring(1);
|
||||||
|
try{
|
||||||
|
Method method = clazz.getDeclaredMethod(methodName, new Class[]{typeClass});
|
||||||
|
method.invoke(obj, new Object[]{getClassTypeValue(typeClass, value)});
|
||||||
|
}catch(Exception ex){
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**通过class类型获取获取对应类型的值*/
|
||||||
|
private Object getClassTypeValue(Class<?> typeClass, Object value){
|
||||||
|
if(typeClass == int.class || value instanceof Integer){
|
||||||
|
if(null == value){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == short.class){
|
||||||
|
if(null == value){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == byte.class){
|
||||||
|
if(null == value){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == double.class){
|
||||||
|
if(null == value){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == long.class){
|
||||||
|
if(null == value){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == String.class){
|
||||||
|
if(null == value){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == boolean.class){
|
||||||
|
if(null == value){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}else if(typeClass == BigDecimal.class){
|
||||||
|
if(null == value){
|
||||||
|
return new BigDecimal(0);
|
||||||
|
}
|
||||||
|
return new BigDecimal(value+"");
|
||||||
|
}else {
|
||||||
|
return typeClass.cast(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**处理字符串 如: abc_dex ---> abcDex*/
|
||||||
|
private String removeLine(String str){
|
||||||
|
if(null != str && str.contains("_")){
|
||||||
|
int i = str.indexOf("_");
|
||||||
|
char ch = str.charAt(i+1);
|
||||||
|
char newCh = (ch+"").substring(0, 1).toUpperCase().toCharArray()[0];
|
||||||
|
String newStr = str.replace(str.charAt(i+1), newCh);
|
||||||
|
String newStr2 = newStr.replace("_", "");
|
||||||
|
return newStr2;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user