. public Page getList(String name, int page, int size) {
String nameNew = name;
if (name == null){
nameNew = “”;
}
// Sort sort;
//if(“升序”.equals(onorunder)){
// sort = Sort.by(Sort.Direction.ASC, depend);
//}else if (“降序”.equals(onorunder)){
//sort = Sort.by(Sort.Direction.DESC, depend);
//}else{
// sort = Sort.by(Sort.Direction.DESC, depend);
// }
// Pageable pageable= PageRequest.of(page-1,size,sort);排序的话替换带你下面一行就好了
Pageable pageable=PageRequest.of(page<=0?0:page-1,size);
Page list = zhjQueryRepository.findAllByNameContaining(nameNew, pageable);
Page processFormDtol= list.map(processFormView -> {
StudentDTO processFormDto = new StudentDTO();
processFormDto.setId(String.valueOf(processFormView.getId()));
processFormDto.setGradeId(processFormView.getGradeId());
if(processFormView.getGradeId()!=null) {
Optional byId = gradeQueryRepository.findById(Long.parseLong(processFormView.getGradeId()));
Grade grade = byId.get();
processFormDto.setGradeName(grade.getGradeName());
}else {
processFormDto.setGradeName(null);
}
processFormDto.setBj(processFormView.getBj());
processFormDto.setName(processFormView.getName());
processFormDto.setRxsj(processFormView.getRxsj());
processFormDto.setXb(processFormView.getXb());
processFormDto.setXskh(processFormView.getXskh());
processFormDto.setZy(processFormView.getZy());
return processFormDto;
});
return processFormDtol;
}
Controller中的代码
@GetMapping(value = "mohu", produces = { "application/json;charset=UTF-8"})
public ResponseCode<List<StudentDTO>> getlistlikename(String name,int page,int size){
ResponseCode<List<StudentDTO>> responseCode = ResponseCode.sucess();
responseCode.setDataInfo(zhjQueryService.getList(name,page,size));
return responseCode;
}