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

把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);
    }

相关文章:

  • 2021-11-27
  • 2021-09-19
  • 2021-05-22
  • 2022-01-18
  • 2022-12-23
  • 2021-10-21
  • 2021-05-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-01-25
  • 2022-12-23
  • 2022-02-17
相关资源
相似解决方案