原代码: 创建Dto给前端返值
@PostMapping({"/question/choice"})
public ResponseEntity findExercises(@RequestBody @NotEmpty(message = "{exercises.id.NotEmpty.message}") List<String> cmd5s) {
List<ChoiceQuestion> contentMd5s = service.findAllByContentMd5In(cmd5s);
List<ChoiceRtnDto> repetitions = contentMd5s
.stream()
.map(e -> new ChoiceRtnDto(e.getContentMd5(), e.getTitle(), e.getPid()))
.collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.ALREADY_REPORTED).body(repetitions);
}
更改后:
@PostMapping({"/question/choice"})
public ResponseEntity findExercises(@RequestBody @NotEmpty(message = "{exercises.id.NotEmpty.message}") List<String> md5List) {
List<Map<String, String>> repetitiveQuestions = new ArrayList<>();
service.findAllByContentMd5In(md5List).forEach(e -> {
Map<String, String> map = new HashMap<>();
map.put("md5", e.getContentMd5());
map.put("name", e.getTitle());
map.put("pid", e.getPid());
repetitiveQuestions.add(map);
});
return ResponseEntity.status(HttpStatus.ALREADY_REPORTED).body(repetitiveQuestions);
}