对象复制/拷贝
代码展示:
/**
* @param {@link }
* @return {@link Result}
* @author tx
* @date 2020-11-03 17:16:25
* @description 查看预警事件信息详情
* @menu 预警事件管理
**/
@RequestMapping(value = "/getWarningEventDetail", method = RequestMethod.GET)
public Result<ContagionEventVO> getWarningEventDetail(@RequestParam("contagionEventId") Long contagionEventId) {
ContagionEventPO contagionEventPO = contagionEventService.selectOneByPrimaryKey(contagionEventId);
ContagionEventVO contagionEventVO = new ContagionEventVO();
BeanUtil.copyProperties(contagionEventPO, contagionEventVO);
return Result.succeed(contagionEventVO);
}
使用 cn.hutool.core.bean.BeanUtil进行对象相同属性的复制操作。
集合复制/拷贝
代码展示:
/**
* @param {@link }
* @return {@link Result}
* @author tx
* @date 2020-11-03 17:16:25
* @description 查看被预警人名单列表
* @menu 预警事件管理
**/
@RequestMapping(value = "/getWarningPeopleListDetail", method = RequestMethod.GET)
public Result<List<WarningPeopleDetailVO>> getWarningPeopleListDetail(@RequestParam("contagionEventId") Long contagionEventId) {
List<ContagionRecordPO> contagionRecordPOS = contagionRecordService.selectListByCustomQuery(CustomQuery.of(ContagionRecordPO.class).andWhere(
WhereCriteria.custom()
.andEqualTo("isDelete", DeleteEnum.NORMAL.getCode())
.andEqualTo("congationEventId", contagionEventId)
).orderByDesc("warningTime")
);
String recordListJson = JSON.toJSONString(contagionRecordPOS);
List<WarningPeopleDetailVO> peopleDetailVOS = JSON.parseArray(recordListJson, WarningPeopleDetailVO.class);
return Result.succeed(peopleDetailVOS);
}
使用范例:
List<User> userList = new ArrayList<>;
String userListJson= JSON.toJSONString(userList );
List<Student> studentList = JSON.parseArray(userListJson, Student.class);