com.luues.util.datawrap.DataWrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-util Show documentation
Show all versions of commons-util Show documentation
A Simple Tool Operations Class
package com.luues.util.datawrap;
import com.alibaba.fastjson.JSONObject;
import java.lang.reflect.Method;
import java.util.ArrayList;
public class DataWrap extends JSONObject{
protected int resultCode = ResultCode.c_200;
protected String resultMsg = "SUCCESS";
public DataWrap(){
this.put("resultCode", resultCode);
this.put("resultMsg", resultMsg);
//this.put("rows", new ArrayList<>());
}
protected Object getFieldValueByName(String fieldName, Object o) {
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase();
String getter = "get" + firstLetter + fieldName.substring(1);
Method method = o.getClass().getMethod(getter, new Class[] {});
Object value = method.invoke(o, new Object[] {});
return value;
} catch (Exception e) {
return null;
}
}
}