【发布时间】:2021-02-23 12:33:45
【问题描述】:
我们正在尝试在此的帮助下进行分页
<dependency>
<groupId>net.kaczmarzyk</groupId>
<artifactId>specification-arg-resolver</artifactId>
<version>2.1.1</version>
</dependency>
使用请求参数很好,但是当我们尝试使用Path variables 时,它会给出异常提示
控制器请求映射注释中不存在请求的路径变量 {destUserId}
以下是我们尝试过的方法
方法一:使用@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;
}
方法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;
}
方法 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;
}
方法 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 只带路径,不带@PathVariable,不带@Conjunction
@RequestMapping("/cf/{destUserId}")
@ResponseBody
public PagedResponse<SystemStock> croudFundReport(@Spec(path = "destUserId", pathVars = "destUserId", spec = Equal.class) Specification<UserData> spec) {
return null;
}
方法6:GetMapping 不带@PathVariable,不带@Conjunction
@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;
}
参考文献
问题是我们可以访问PathVariable 作为方法参数,但是当我们尝试在pathVars 中指定它时,在上述情况下执行没有到达我们的控制器并且我们得到了同样的上述异常。有什么帮助吗?
【问题讨论】:
标签: java spring-boot pagination request-mapping path-variables