[英]Pagination in Spring Boot via path variable - Requested path variable is not present in Controller request mapping annotations
We are trying to do pagination with the help of this我们正在尝试借助此功能进行分页
<dependency>
<groupId>net.kaczmarzyk</groupId>
<artifactId>specification-arg-resolver</artifactId>
<version>2.1.1</version>
</dependency>
With request parameters its fine, but when we try with Path variables
its giving exception saying使用请求参数很好,但是当我们尝试使用
Path variables
时,它给出异常说
Requested path variable {destUserId} is not present in Controller request mapping annotations Controller 请求映射注释中不存在请求的路径变量 {destUserId}
The following are the methods we tried以下是我们尝试过的方法
Method-1: With @PathVariable方法一:使用@PathVariable
@RequestMapping(method = RequestMethod.GET, value = "/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@PathVariable(name = "destUserId") String eventId,
@Conjunction (value = {
@Or(value = @Spec(path = "metaType", params = {"meta_type"}, spec = Equal.class))},
and = @Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class)) Specification<UserData> spec) {
return null;
}
Method-2: Without @PathVariable方法 2:不使用 @PathVariable
@RequestMapping(method = RequestMethod.GET, value = "/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@Conjunction (value = {
@Or(value = @Spec(path = "metaType", params = {"meta_type"}, spec = Equal.class))},
and = @Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class)) Specification<UserData> spec) {
return null;
}
Method-3: RequestMapping with just path and with @PathVariable方法 3:仅使用路径和 @PathVariable 的 RequestMapping
@RequestMapping("/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@PathVariable(name = "destUserId") String eventId,
@Conjunction (value = {
@Or(value = @Spec(path = "metaType", params = {"meta_type"}, spec = Equal.class))},
and = @Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class)) Specification<UserData> spec) {
return null;
}
Method-4: RequestMapping with just path and without @PathVariable方法 4:仅使用路径而不使用 @PathVariable 的 RequestMapping
@RequestMapping("/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@Conjunction (value = {
@Or(value = @Spec(path = "metaType", params = {"meta_type"}, spec = Equal.class))},
and = @Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class)) Specification<UserData> spec) {
return null;
}
Method-5: RequestMapping with just path, without @PathVariable, without @Conjunction方法 5:仅使用路径的 RequestMapping,不带 @PathVariable,不带 @Conjunction
@RequestMapping("/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class) Specification<UserData> spec) {
return null;
}
Method-6: GetMapping without @PathVariable, without @Conjunction方法6:没有@PathVariable,没有@Conjunction 的GetMapping
@GetMapping(path = "/cf/{destUserId}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class) Specification<UserData> spec) {
return null;
}
References参考
The problem is we can access the PathVariable
as a method argument, but when we try to specify it in that in pathVars
in the above cases execution is not reaching our Controller and we are getting the same above exception.问题是我们可以将
PathVariable
作为方法参数访问,但是当我们尝试在上述情况下在pathVars
中指定它时,执行没有到达我们的 Controller 并且我们得到了相同的上述异常。 Any help?有什么帮助吗?
One thing I noticed you used GetMapping only in the last example.我注意到您只在最后一个示例中使用了 GetMapping 的一件事。 Is there reason for using RequestMapping?
有使用 RequestMapping 的理由吗?
Is there a specific reason to not use [JPA pagination][https://www.baeldung.com/jpa-pagination]?是否有不使用 [JPA 分页][https://www.baeldung.com/jpa-pagination] 的特定原因?
Have you tried the following?您是否尝试过以下操作?
@GetMapping(path = "/cf/{destUserId}", produces = MediaType.APPLICATION_JSON_VALUE)
public PagedResponse<SystemStock> croudFundReport( @PathVariable(name = "destUserId") final String destUserId) {
// TODO implementation
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.