Jackson仍返回懒加载字段JSON值,启用懒加载后API反而变慢
附你的代码片段:
Student实体类
public class Student { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "status_id") private StudentStatus statusID; }
Controller代码
public Page<StudentDTO> getAllStudents(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size, @RequestParam(name = "filter", required = false) String fieldName, @RequestParam(name = "value", required = false) String fieldValue) { Pageable pageable = PageRequest.of(page, size); Specification<Student> spec = StudentSpecification.hasFieldWithValueLike(fieldName,fieldValue); return studentService.getStudents(spec, pageable); }
Service代码
public Page<StudentDTO> getStudents(Specification<Student> spec, Pageable pageable) { Page<Student> studentPage = studentRepository.findAll(spec, pageable); return studentPage.map(student -> studentMapper.toDTO(student)); }
内容的提问来源于stack exchange,提问作者vunhatchuong
相关产品推荐
相关产品推荐

