本文整理了Java中cn.hutool.core.bean.BeanUtil.copyProperties()
方法的一些代码示例,展示了BeanUtil.copyProperties()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BeanUtil.copyProperties()
方法的具体详情如下:
包路径:cn.hutool.core.bean.BeanUtil
类名称:BeanUtil
方法名:copyProperties
[英]复制Bean对象属性
[中]复制豆对象属性
代码示例来源:origin: looly/hutool
/**
* 复制Bean对象属性
*
* @param source 源Bean对象
* @param target 目标Bean对象
*/
public static void copyProperties(Object source, Object target) {
copyProperties(source, target, CopyOptions.create());
}
代码示例来源:origin: looly/hutool
/**
* 复制Bean对象属性
*
* @param source 源Bean对象
* @param target 目标Bean对象
*/
public static void copyProperties(Object source, Object target) {
copyProperties(source, target, CopyOptions.create());
}
代码示例来源:origin: looly/hutool
/**
* 对象或Map转Bean
*
* @param source Bean对象或Map
* @param clazz 目标的Bean类型
* @return Bean对象
* @since 4.1.20
*/
public static <T> T toBean(Object source, Class<T> clazz) {
final T target = ReflectUtil.newInstance(clazz);
copyProperties(source, target);
return target;
}
代码示例来源:origin: looly/hutool
/**
* 对象或Map转Bean
*
* @param source Bean对象或Map
* @param clazz 目标的Bean类型
* @return Bean对象
* @since 4.1.20
*/
public static <T> T toBean(Object source, Class<T> clazz) {
final T target = ReflectUtil.newInstance(clazz);
copyProperties(source, target);
return target;
}
代码示例来源:origin: looly/hutool
/**
* 复制Bean对象属性<br>
* 限制类用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类
*
* @param source 源Bean对象
* @param target 目标Bean对象
* @param ignoreProperties 不拷贝的的属性列表
*/
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
}
代码示例来源:origin: looly/hutool
/**
* 复制Bean对象属性<br>
* 限制类用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类
*
* @param source 源Bean对象
* @param target 目标Bean对象
* @param ignoreProperties 不拷贝的的属性列表
*/
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
}
代码示例来源:origin: stylefeng/Guns
/**
* 添加字典类型
*
* @author fengshuonan
* @Date 2018/12/23 5:25 PM
*/
private void addDictType(DictDto dictDto) {
Dict dict = new Dict();
BeanUtil.copyProperties(dictDto, dict);
//类型的父级id都为0
dict.setPid(0L);
this.insert(dict);
}
代码示例来源:origin: stylefeng/Guns
/**
* 部门详情
*
* @author fengshuonan
* @Date 2018/12/23 4:57 PM
*/
@RequestMapping(value = "/detail/{deptId}")
@Permission
@ResponseBody
public Object detail(@PathVariable("deptId") Long deptId) {
Dept dept = deptService.selectById(deptId);
DeptDto deptDto = new DeptDto();
BeanUtil.copyProperties(dept, deptDto);
deptDto.setPName(ConstantFactory.me().getDeptName(deptDto.getPid()));
return deptDto;
}
代码示例来源:origin: stylefeng/Guns
/**
* 添加字典子类型
*
* @author fengshuonan
* @Date 2018/12/23 5:25 PM
*/
private void addDictItem(DictDto dictDto) {
Dict dict = new Dict();
BeanUtil.copyProperties(dictDto, dict);
//字典的父级id为字典tyeId
dict.setPid(dictDto.getDictTypeId());
this.insert(dict);
}
代码示例来源:origin: stylefeng/Guns
/**
* 获取菜单信息
*
* @author fengshuonan
* @Date 2018/12/23 5:53 PM
*/
@RequestMapping(value = "/getMenuInfo")
@ResponseBody
public ResponseData getMenuInfo(@RequestParam Long menuId) {
if (ToolUtil.isEmpty(menuId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
Menu menu = this.menuService.selectById(menuId);
MenuDto menuDto = new MenuDto();
BeanUtil.copyProperties(menu, menuDto);
//设置pid和父级名称
menuDto.setPid(ConstantFactory.me().getMenuIdByCode(menuDto.getPcode()));
menuDto.setPcodeName(ConstantFactory.me().getMenuNameByCode(menuDto.getPcode()));
return ResponseData.success(menuDto);
}
代码示例来源:origin: stylefeng/Guns
/**
* 编辑角色
*
* @author fengshuonan
* @Date 2018/12/23 6:40 PM
*/
@Transactional(rollbackFor = Exception.class)
public void editRole(RoleDto roleDto) {
if (ToolUtil.isOneEmpty(roleDto, roleDto.getName(), roleDto.getPid(), roleDto.getDescription())) {
throw new RequestEmptyException();
}
Role old = this.selectById(roleDto.getRoleId());
BeanUtil.copyProperties(roleDto, old);
this.updateById(old);
//删除缓存
CacheUtil.removeAll(Cache.CONSTANT);
}
代码示例来源:origin: stylefeng/Guns
/**
* 根据请求的父级菜单编号设置pcode和层级
*
* @author fengshuonan
* @Date 2018/12/23 5:54 PM
*/
public Menu menuSetPcode(MenuDto menuParam) {
Menu resultMenu = new Menu();
BeanUtil.copyProperties(menuParam, resultMenu);
if (ToolUtil.isEmpty(menuParam.getPid()) || menuParam.getPid().equals(0L)) {
resultMenu.setPcode("0");
resultMenu.setPcodes("[0],");
resultMenu.setLevels(1);
} else {
Long pid = menuParam.getPid();
Menu pMenu = this.selectById(pid);
Integer pLevels = pMenu.getLevels();
resultMenu.setPcode(pMenu.getCode());
//如果编号和父编号一致会导致无限递归
if (menuParam.getCode().equals(menuParam.getPcode())) {
throw new ServiceException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
}
resultMenu.setLevels(pLevels + 1);
resultMenu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],");
}
return resultMenu;
}
代码示例来源:origin: daijiejay/daijie
public static <T> T newInstance(Class<T> className, Object source) {
try {
T newObj= className.newInstance();
BeanUtil.copyProperties(source, newObj);
return newObj;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: cn.hutool/hutool-all
/**
* 对象或Map转Bean
*
* @param source Bean对象或Map
* @param clazz 目标的Bean类型
* @return Bean对象
* @since 4.1.20
*/
public static <T> T toBean(Object source, Class<T> clazz) {
final T target = ReflectUtil.newInstance(clazz);
copyProperties(source, target);
return target;
}
代码示例来源:origin: cn.hutool/hutool-all
/**
* 复制Bean对象属性
*
* @param source 源Bean对象
* @param target 目标Bean对象
*/
public static void copyProperties(Object source, Object target) {
copyProperties(source, target, CopyOptions.create());
}
代码示例来源:origin: daijiejay/daijie
@Override
public T apply(E input) {
T entity = null;
try {
entity = className.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
BeanUtil.copyProperties(input, entity, CopyOptions.create().setIgnoreError(true));
return entity;
}
});
代码示例来源:origin: cn.hutool/hutool-all
/**
* 复制Bean对象属性<br>
* 限制类用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类
*
* @param source 源Bean对象
* @param target 目标Bean对象
* @param ignoreProperties 不拷贝的的属性列表
*/
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
}
代码示例来源:origin: xkcoding/spring-boot-demo
public static OnlineUser create(User user) {
OnlineUser onlineUser = new OnlineUser();
BeanUtil.copyProperties(user, onlineUser);
// 脱敏
onlineUser.setPhone(StrUtil.hide(user.getPhone(), 3, 7));
onlineUser.setEmail(StrUtil.hide(user.getEmail(), 1, StrUtil.indexOfIgnoreCase(user.getEmail(), Consts.SYMBOL_EMAIL)));
return onlineUser;
}
}
代码示例来源:origin: xkcoding/spring-boot-demo
/**
* 更新用户
*
* @param user 用户实体
* @param id 主键id
* @return 更新成功 {@code true} 更新失败 {@code false}
*/
@Override
public Boolean update(User user, Long id) {
User exist = getUser(id);
if (StrUtil.isNotBlank(user.getPassword())) {
String rawPass = user.getPassword();
String salt = IdUtil.simpleUUID();
String pass = SecureUtil.md5(rawPass + Const.SALT_PREFIX + salt);
user.setPassword(pass);
user.setSalt(salt);
}
BeanUtil.copyProperties(user, exist, CopyOptions.create().setIgnoreNullValue(true));
exist.setLastUpdateTime(new DateTime());
return userDao.update(exist, id) > 0;
}
内容来源于网络,如有侵权,请联系作者删除!