Fork me on GitHub
如果对您有帮助,麻烦您点赞留言吧~~~

BeanUtils.copyProperties实现po,vo,dto之间的转换

缘由:项目中各类bean对象转换,在老项目里看到一堆的从A类get出来,再set到B类...简直看的头大

BeanUtils.copyProperties的作用

把A类中与B类中相同的变量名称的值复制到B类。

举个例子,将接收到的userDto转换成po

	@PostMapping("/user")
    public AjaxResult addUser(@RequestBody UserDto userDto) {
        UserEntity user = new UserEntity();
        BeanUtils.copyProperties(userDto, user);
        String salt = UUID.randomUUID().toString().replace("-", "");
        user.setSalt(salt);
        return AjaxResult.success(userService.save(user), Constant.Rest.INSERT_SUCCESS);
    }
posted @ 2018-06-26 15:12  jarjune  阅读(4229)  评论(0编辑  收藏  举报