Package tech.mgl.core.utils
Class MGL_BeanUtils
java.lang.Object
tech.mgl.core.utils.MGL_BeanUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbean转换成listbean2Map(T t) static Stringbean2StringValues(Object bean) 把对象的key=value的形式按ASCII顺序拼成串返回static Stringbean2StringValues(Object bean, String dateFormat) 把对象的key=value的形式按ASCII顺序拼成串返回static <T,V> V static <T> TcopyAttribute(Object target, Object sourceObj) 复制属性static <T> TcopyAttribute(Object target, Object sourceObj, List<String> copyFields) 可以指定复制哪些字段static <T> TcopyAttribute(Object target, Object sourceObj, List<String> copyFields, boolean exeSrcNull) static <T> TcopyAttribute(Object target, Object sourceObj, List<String> copyFields, List<String> excludeFields, boolean exeSrcNull) 复制属性static <T> TcopyAttributeWithExclude(Object target, Object sourceObj, List<String> excludeFields) static <T> Tstatic <T> Objectstatic <T,R> R 获取对象的指定字段值。static <T,R> R getValueWithDefault(T t, String fieldName, R defaultValue) static <T,R> R getValueWithDefault(T t, MFunction<T, ?> fieldName, R defaultValue) 获取对象的指定字段值。static <T> T将一个 Map 对象转化为一个 JavaBeanstatic <T> Tmap转bean 泛型为invalid input: '<'string,string>static <T> Tstatic <T> T给某个对象设置给定的属性值toMap(T bean, boolean keepNull) 将一个 JavaBean 对象转化为一个 Map
-
Constructor Details
-
MGL_BeanUtils
public MGL_BeanUtils()
-
-
Method Details
-
copyAttribute
复制属性- Parameters:
target- 目标类sourceObj- 原类- Throws:
Exception- Exception
-
copyAttribute
public static <T> T copyAttribute(Object target, Object sourceObj, List<String> copyFields) throws Exception 可以指定复制哪些字段- Parameters:
target- targetsourceObj- sourceObjcopyFields- copyFields- Throws:
Exception- Exception
-
copyAttributeWithExclude
public static <T> T copyAttributeWithExclude(Object target, Object sourceObj, List<String> excludeFields) throws Exception - Throws:
Exception
-
convert
- Throws:
Exception
-
copyAttribute
public static <T> T copyAttribute(Object target, Object sourceObj, List<String> copyFields, boolean exeSrcNull) throws Exception - Throws:
Exception
-
copyAttribute
public static <T> T copyAttribute(Object target, Object sourceObj, List<String> copyFields, List<String> excludeFields, boolean exeSrcNull) throws Exception 复制属性- Parameters:
target- 目标类,被设值的类sourceObj- 原类,要把值传给目标类的原类exeSrcNull- 是否原属性值为空时执行复制操作 默认为false不执行- Throws:
Exception- Exception
-
bean2List
bean转换成list- Parameters:
beanInstance- beanInstanceexceptionField- exceptionField- Returns:
- List
-
toMap
将一个 JavaBean 对象转化为一个 Map- Parameters:
bean- 要转化的JavaBean 对象keepNull- 当空时也转 默认false- Returns:
- 转化出来的 Map 对象
-
map2Bean
将一个 Map 对象转化为一个 JavaBean- Parameters:
map- 包含属性值的 maptype- 要转化的类型- Returns:
- 转化出来的 JavaBean 对象
-
mapToBean
map转bean 泛型为invalid input: '<'string,string>- Type Parameters:
T-- Parameters:
map- maptype- type
-
bean2Map
-
setValues
public static <T> T setValues(T t, Map<String, Object> values, boolean copyDBFiled) throws IntrospectionException, IllegalAccessException, InvocationTargetException给某个对象设置给定的属性值- Type Parameters:
T-- Parameters:
t- 对象values- 值- Throws:
IntrospectionExceptionIllegalAccessExceptionInvocationTargetException
-
setValues
public static <T> T setValues(T t, Map<String, Object> values) throws IntrospectionException, IllegalAccessException, InvocationTargetException -
getValue
获取对象的指定字段值。- Type Parameters:
T- 对象类型- Parameters:
t- 对象实例fieldName- 字段名称- Returns:
- 字段的值,如果获取失败返回 null
-
getValueWithDefault
获取对象的指定字段值。- Type Parameters:
T- 对象类型- Parameters:
t- 对象实例fieldName- 字段名称- Returns:
- 字段的值,如果获取失败返回 null
-
getValue
-
getValueWithDefault
-
bean2StringValues
把对象的key=value的形式按ASCII顺序拼成串返回- Parameters:
bean- bean- Returns:
- String
- Throws:
Exception- Exception
-
getBean
-
bean2StringValues
把对象的key=value的形式按ASCII顺序拼成串返回- Parameters:
bean- beandateFormat- 日期格式- Returns:
- String
- Throws:
Exception- Exception
-