去除重复代码 一 使用spring BeanUtils

//利用属性拷贝工具消除重复代码
@Slf4j
public class BeanUtilsLearn {
    public static void main(String[] args) {
        UserDTO userDTO = UserDTO.builder().id(1).username("admin").build();
        User user = new User();
        BeanUtils.copyProperties(userDTO,user);
        log.debug(user.getUsername());
    }
}

你可能感兴趣的:(代码优化)