hutool 工具 map 转驼峰

Map工具-MapUtil
https://www.tabnine.com/code/java/methods/cn.hutool.core.map.MapUtil/toCamelCaseMap
How to usetoCamelCaseMapmethodincn.hutool.core.map.MapUtil

BeanUtil.fillBeanWithMap(...)
/**
 * 使用Map填充Bean对象
 * 
 * @param <T> Bean类型
 * @param map Map
 * @param bean Bean
 * @param isToCamelCase 是否将Map中的下划线风格key转换为驼峰风格
 * @param copyOptions 属性复制选项 {@link CopyOptions}
 * @return Bean
 * @since 3.3.1
 */
public static <T> T fillBeanWithMap(Map<?, ?> map, T bean, boolean isToCamelCase, CopyOptions copyOptions) {
  if (MapUtil.isEmpty(map)) {
    return bean;
  }
  if (isToCamelCase) {
    map = MapUtil.toCamelCaseMap(map);
  }
  return BeanCopier.create(map, bean, copyOptions).copy();
}
BeanUtil.fillBeanWithMap(...)
/**
 * 使用Map填充Bean对象
 * 
 * @param <T> Bean类型
 * @param map Map
 * @param bean Bean
 * @param isToCamelCase 是否将Map中的下划线风格key转换为驼峰风格
 * @param copyOptions 属性复制选项 {@link CopyOptions}
 * @return Bean
 * @since 3.3.1
 */
public static <T> T fillBeanWithMap(Map<?, ?> map, T bean, boolean isToCamelCase, CopyOptions copyOptions) {
  if (MapUtil.isEmpty(map)) {
    return bean;
  }
  if (isToCamelCase) {
    map = MapUtil.toCamelCaseMap(map);
  }
  return BeanCopier.create(map, bean, copyOptions).copy();
}
Record.toBean(...)
public <T> T toBean(Class<T> beanClass){
  return (T)BeanUtil.mapToBean(MapUtil.toCamelCaseMap(this),beanClass,true);
  //return BeanUtil.fillBeanWithMap(this,beanClass.newInstance(),true,)
}
BeanUtil.fillBeanWithMap(...)
/**
 * 使用Map填充Bean对象
 * 
 * @param <T> Bean类型
 * @param map Map
 * @param bean Bean
 * @param isToCamelCase 是否将Map中的下划线风格key转换为驼峰风格
 * @param copyOptions 属性复制选项 {@link CopyOptions}
 * @return Bean
 * @since 3.3.1
 */
public static <T> T fillBeanWithMap(Map<?, ?> map, T bean, boolean isToCamelCase, CopyOptions copyOptions) {
  if (MapUtil.isEmpty(map)) {
    return bean;
  }
  if (isToCamelCase) {
    map = MapUtil.toCamelCaseMap(map);
  }
  return BeanCopier.create(map, bean, copyOptions).copy();
}
posted @ 2023-12-04 08:57  寒冷的雨呢  阅读(642)  评论(0编辑  收藏  举报