Class MGL_BeanUtils

java.lang.Object
tech.mgl.core.utils.MGL_BeanUtils

public class MGL_BeanUtils extends Object
  • Constructor Details

    • MGL_BeanUtils

      public MGL_BeanUtils()
  • Method Details

    • copyAttribute

      public static <T> T copyAttribute(Object target, Object sourceObj) throws Exception
      复制属性
      Parameters:
      target - 目标类
      sourceObj - 原类
      Throws:
      Exception - Exception
    • copyAttribute

      public static <T> T copyAttribute(Object target, Object sourceObj, List<String> copyFields) throws Exception
      可以指定复制哪些字段
      Parameters:
      target - target
      sourceObj - sourceObj
      copyFields - copyFields
      Throws:
      Exception - Exception
    • copyAttributeWithExclude

      public static <T> T copyAttributeWithExclude(Object target, Object sourceObj, List<String> excludeFields) throws Exception
      Throws:
      Exception
    • convert

      public static <T, V> V convert(T t, Class<V> vClass) throws Exception
      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

      public static List<Object> bean2List(Object beanInstance, String[] exceptionField)
      bean转换成list
      Parameters:
      beanInstance - beanInstance
      exceptionField - exceptionField
      Returns:
      List
    • toMap

      public static <T> Map<String,Object> toMap(T bean, boolean keepNull)
      将一个 JavaBean 对象转化为一个 Map
      Parameters:
      bean - 要转化的JavaBean 对象
      keepNull - 当空时也转 默认false
      Returns:
      转化出来的 Map 对象
    • map2Bean

      public static <T> T map2Bean(Map<String,Object> map, Class<T> type)
      将一个 Map 对象转化为一个 JavaBean
      Parameters:
      map - 包含属性值的 map
      type - 要转化的类型
      Returns:
      转化出来的 JavaBean 对象
    • mapToBean

      public static <T> T mapToBean(Map<String,String> map, Class<T> type)
      map转bean 泛型为invalid input: '<'string,string>
      Type Parameters:
      T -
      Parameters:
      map - map
      type - type
    • bean2Map

      public static <T> Map<String,Object> bean2Map(T t)
    • 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:
      IntrospectionException
      IllegalAccessException
      InvocationTargetException
    • setValues

      public static <T> T setValues(T t, Map<String,Object> values) throws IntrospectionException, IllegalAccessException, InvocationTargetException
      Throws:
      IntrospectionException
      IllegalAccessException
      InvocationTargetException
    • getValue

      public static <T, R> R getValue(T t, MFunction<T,R> fieldName)
      获取对象的指定字段值。
      Type Parameters:
      T - 对象类型
      Parameters:
      t - 对象实例
      fieldName - 字段名称
      Returns:
      字段的值,如果获取失败返回 null
    • getValueWithDefault

      public static <T, R> R getValueWithDefault(T t, MFunction<T,?> fieldName, R defaultValue)
      获取对象的指定字段值。
      Type Parameters:
      T - 对象类型
      Parameters:
      t - 对象实例
      fieldName - 字段名称
      Returns:
      字段的值,如果获取失败返回 null
    • getValue

      public static <T> Object getValue(T t, String fieldName)
    • getValueWithDefault

      public static <T, R> R getValueWithDefault(T t, String fieldName, R defaultValue)
    • bean2StringValues

      public static String bean2StringValues(Object bean) throws Exception
      把对象的key=value的形式按ASCII顺序拼成串返回
      Parameters:
      bean - bean
      Returns:
      String
      Throws:
      Exception - Exception
    • getBean

      public static <T> T getBean(Object object, Class<T> clS)
    • bean2StringValues

      public static String bean2StringValues(Object bean, String dateFormat) throws Exception
      把对象的key=value的形式按ASCII顺序拼成串返回
      Parameters:
      bean - bean
      dateFormat - 日期格式
      Returns:
      String
      Throws:
      Exception - Exception