美文网首页
spring BeanUtils 工具实现对象之间的copy 属

spring BeanUtils 工具实现对象之间的copy 属

作者: 万事俱备就差一个程序员了 | 来源:发表于2021-12-08 15:42 被阅读0次

一般我们会开发中会遇到返回用户信息的时候,不需要返回密码或者其他参数,这时候我们需要重新定义一个VO类去除不需要的参数,将原对象copy到VO类中

使用spring的BeanUtils可以实现对象的copy

语法:

BeanUtils.copyProperties(source, target);

import org.springframework.beans.BeanUtils;

SdbDbUser user =userServer.getUserInfo(toUser);

UserVO userVo=newUserVO();BeanUtils.copyProperties(user, userVo);

相关文章

网友评论

      本文标题:spring BeanUtils 工具实现对象之间的copy 属

      本文链接:https://www.haomeiwen.com/subject/cvetfrtx.html