本文整理了Java中cn.hutool.core.bean.BeanUtil.beanToMap()
方法的一些代码示例,展示了BeanUtil.beanToMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanUtil.beanToMap()
方法的具体详情如下:
包路径:cn.hutool.core.bean.BeanUtil
类名称:BeanUtil
方法名:beanToMap
[英]对象转Map,不进行驼峰转下划线,不忽略值为空的字段
[中]对象转地图不进行驼峰转下划线,不忽略值为空的字段
代码示例来源:origin: looly/hutool
/**
* 对象转Map,不进行驼峰转下划线,不忽略值为空的字段
*
* @param bean bean对象
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean) {
return beanToMap(bean, false, false);
}
代码示例来源:origin: looly/hutool
/**
* 对象转Map,不进行驼峰转下划线,不忽略值为空的字段
*
* @param bean bean对象
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean) {
return beanToMap(bean, false, false);
}
代码示例来源:origin: looly/hutool
/**
* 对象转Map
*
* @param bean bean对象
* @param targetMap 目标的Map
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return Map
* @since 3.2.3
*/
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, final boolean isToUnderlineCase, boolean ignoreNullValue) {
if (bean == null) {
return null;
}
return beanToMap(bean, targetMap, ignoreNullValue, new Editor<String>() {
@Override
public String edit(String key) {
return isToUnderlineCase ? StrUtil.toUnderlineCase(key) : key;
}
});
}
代码示例来源:origin: looly/hutool
/**
* 对象转Map
*
* @param bean bean对象
* @param targetMap 目标的Map
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return Map
* @since 3.2.3
*/
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, final boolean isToUnderlineCase, boolean ignoreNullValue) {
if (bean == null) {
return null;
}
return beanToMap(bean, targetMap, ignoreNullValue, new Editor<String>() {
@Override
public String edit(String key) {
return isToUnderlineCase ? StrUtil.toUnderlineCase(key) : key;
}
});
}
代码示例来源:origin: looly/hutool
/**
* 对象转Map
*
* @param bean bean对象
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
return beanToMap(bean, new LinkedHashMap<String, Object>(), isToUnderlineCase, ignoreNullValue);
}
代码示例来源:origin: looly/hutool
/**
* 对象转Map
*
* @param bean bean对象
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return Map
*/
public static Map<String, Object> beanToMap(Object bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
return beanToMap(bean, new LinkedHashMap<String, Object>(), isToUnderlineCase, ignoreNullValue);
}
代码示例来源:origin: stylefeng/Guns
/**
* 过滤不安全字段并转化为map
*/
public static Map<String, Object> removeUnSafeFields(User user) {
if (user == null) {
return new HashMap<>();
} else {
Map<String, Object> map = BeanUtil.beanToMap(user);
map.remove("password");
map.remove("salt");
map.put("birthday", DateUtil.formatDate(user.getBirthday()));
return map;
}
}
}
代码示例来源:origin: looly/hutool
/**
* 将值对象转换为Dict<br>
* 类名会被当作表名,小写第一个字母
*
* @param <T> Bean类型
* @param bean 值对象
* @return 自己
*/
public <T> Dict parseBean(T bean) {
Assert.notNull(bean, "Bean class must be not null");
this.putAll(BeanUtil.beanToMap(bean));
return this;
}
代码示例来源:origin: looly/hutool
/**
* 将值对象转换为Dict<br>
* 类名会被当作表名,小写第一个字母
*
* @param <T> Bean类型
* @param bean 值对象
* @return 自己
*/
public <T> Dict parseBean(T bean) {
Assert.notNull(bean, "Bean class must be not null");
this.putAll(BeanUtil.beanToMap(bean));
return this;
}
代码示例来源:origin: looly/hutool
/**
* 将值对象转换为Dict<br>
* 类名会被当作表名,小写第一个字母
*
* @param <T> Bean类型
* @param bean 值对象
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return 自己
*/
public <T> Dict parseBean(T bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
Assert.notNull(bean, "Bean class must be not null");
this.putAll(BeanUtil.beanToMap(bean, isToUnderlineCase, ignoreNullValue));
return this;
}
代码示例来源:origin: looly/hutool
/**
* 将值对象转换为Dict<br>
* 类名会被当作表名,小写第一个字母
*
* @param <T> Bean类型
* @param bean 值对象
* @param isToUnderlineCase 是否转换为下划线模式
* @param ignoreNullValue 是否忽略值为空的字段
* @return 自己
*/
public <T> Dict parseBean(T bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
Assert.notNull(bean, "Bean class must be not null");
this.putAll(BeanUtil.beanToMap(bean, isToUnderlineCase, ignoreNullValue));
return this;
}
代码示例来源:origin: looly/hutool
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map<?, ?> convertInternal(Object value) {
Map map = null;
if(value instanceof Map){
map = MapUtil.createMap(TypeUtil.getClass(this.mapType));
convertMapToMap((Map)value, map);
}else if(BeanUtil.isBean(value.getClass())){
map = BeanUtil.beanToMap(value);
}else{
throw new UnsupportedOperationException(StrUtil.format("Unsupport toMap value type: {}", value.getClass().getName()));
}
return map;
}
代码示例来源:origin: looly/hutool
map.putAll((Map) obj);
} else {
map = BeanUtil.beanToMap(obj, new TreeMap<String, Object>(comparator), false, false);
代码示例来源:origin: looly/hutool
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map<?, ?> convertInternal(Object value) {
Map map = null;
if(value instanceof Map){
map = MapUtil.createMap(TypeUtil.getClass(this.mapType));
convertMapToMap((Map)value, map);
}else if(BeanUtil.isBean(value.getClass())){
map = BeanUtil.beanToMap(value);
}else{
throw new UnsupportedOperationException(StrUtil.format("Unsupport toMap value type: {}", value.getClass().getName()));
}
return map;
}
代码示例来源:origin: looly/hutool
map.putAll((Map) obj);
} else {
map = BeanUtil.beanToMap(obj, new TreeMap<String, Object>(comparator), false, false);
代码示例来源:origin: stylefeng/Guns
/**
* 查询操作日志详情
*
* @author fengshuonan
* @Date 2018/12/23 5:34 PM
*/
@RequestMapping("/detail/{id}")
@Permission(Const.ADMIN_NAME)
@ResponseBody
public Object detail(@PathVariable Long id) {
OperationLog operationLog = operationLogService.selectById(id);
Map<String, Object> stringObjectMap = BeanUtil.beanToMap(operationLog);
return super.warpObject(new LogWarpper(stringObjectMap));
}
代码示例来源:origin: stylefeng/Guns
/**
* 跳转到修改通知
*
* @author fengshuonan
* @Date 2018/12/23 6:06 PM
*/
@RequestMapping("/notice_update/{noticeId}")
public String noticeUpdate(@PathVariable Long noticeId, Model model) {
Notice notice = this.noticeService.selectById(noticeId);
model.addAllAttributes(BeanUtil.beanToMap(notice));
LogObjectHolder.me().set(notice);
return PREFIX + "notice_edit.html";
}
代码示例来源:origin: stylefeng/Guns
/**
* 查看角色
*
* @author fengshuonan
* @Date 2018/12/23 6:31 PM
*/
@RequestMapping(value = "/view/{roleId}")
@ResponseBody
public ResponseData view(@PathVariable Long roleId) {
if (ToolUtil.isEmpty(roleId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
Role role = this.roleService.selectById(roleId);
Map<String, Object> roleMap = BeanUtil.beanToMap(role);
Long pid = role.getPid();
String pName = ConstantFactory.me().getSingleRoleName(pid);
roleMap.put("pName", pName);
return ResponseData.success(roleMap);
}
代码示例来源:origin: looly/hutool
rowMap = BeanUtil.beanToMap(rowBean, new LinkedHashMap<String, Object>(), false, false);
} else {
rowMap = BeanUtil.beanToMap(rowBean, new TreeMap<String, Object>(getInitedAliasComparator()), false, false);
代码示例来源:origin: stylefeng/Guns
/**
* 跳转到查看用户详情页面
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("/user_info")
public String userInfo(Model model) {
Long userId = ShiroKit.getUserNotNull().getId();
User user = this.userService.selectById(userId);
model.addAllAttributes(BeanUtil.beanToMap(user));
model.addAttribute("roleName", ConstantFactory.me().getRoleName(user.getRoleId()));
model.addAttribute("deptName", ConstantFactory.me().getDeptName(user.getDeptId()));
LogObjectHolder.me().set(user);
return PREFIX + "user_view.html";
}
内容来源于网络,如有侵权,请联系作者删除!