Get Parameters from QueryDSL Predicate Object

I am using the QueryDSL predicate object with spring REST endpoint to retrieve and query parameter values.

@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);

}

The student class contains the studentId and studentName attributes ;

Now, if someone calls https: // hostname / {subjectId} / students? studentId = 1234 & studentName = test

Then the above code generates a predicate object with parameters. But I need to get above 2 parameter values ​​from the predicate object for further processing, except for the db request. I do not see any helper method from the predicate object to retrieve the values. So how can I do this?

+4
source share
1

.
.

predicate.toString(); --- > user.Studentid = 1234 && & user.studentName =
.

:

predicate.getClass()); ---- > ,

class com.querydsl.core.types.PredicateOperation ( )

class com.querydsl.core.types.dsl.BooleanOperation ( ).

, getArgs().

+1

Source: https://habr.com/ru/post/1694569/


All Articles