我使用带有 Spring REST 端点的 QueryDSL 谓词对象来检索和查询参数值。
@GetMapping("/{subjectId}/students")
@RolesAllowed( {Roles.PLATFORM_ADMIN, Roles.USER})
public List<StudentResponse> getAllStudents(@PathVariable final String subjectId,
@QuerydslPredicate(root = Student.class) final Predicate predicate) {
final Predicate searchPredicate = studentPredicate()
.predicate(predicate)
.subjectId(subjectId)
.build();
return studentService.findBySubjectId(subjectId, searchPredicate);
}
Run Code Online (Sandbox Code Playgroud)
Student类包含studentId和studentName属性;
现在,如果有人调用https://hostname/ {subjectId}/students?studentId=1234&studentName=test
然后上面的代码生成带有参数值的谓词对象。但是我需要从谓词对象中获取以上 2 个参数值,以便除了数据库查询之外进行进一步处理。我没有看到谓词对象有任何支持方法来检索值。那么我该怎么做呢?