BeanUtils.copyProperties(A,B)有两个包的引用,区别如下:
- package org.apache.commons.beanutils;
BeanUtils.copyProperties(A,B);
是B中的值付给A
- package org.springframework.beans;
BeanUtils.copyProperties(A,B);
是A中的值付给B。
使用实例:
List<MessageManageDTO> messageManageDTOS = new ArrayList<>();
for (KqMessageManageEntity messageManageEntity:page.getContent()){
MessageManageDTO messageManageDTO = new MessageManageDTO();
//把KqMessageManageEntity的属性赋值给MessageManageDTO
BeanUtils.copyProperties(messageManageEntity,messageManageDTO);
messageManageDTO.setSendDate(messageManageEntity.getSendTime().getTime()+"");
messageManageDTOS.add(messageManageDTO);
}
Map<String,Object> result= new HashMap<>();
result.put("data",messageManageDTOS);
result.put("pageNum",page.getTotalPages());
result.put("limit",page.getTotalElements());
response.setResult(result);
return response;