You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 01:44:56