仅当我根据请求发送更多参数时,Spring Boot 才无法识别我的 Controller 。例如:
如果我发送正常的GET请求,Spring Boot识别我的 Controller :
http://localhost/idp/oauth/123/authorize
如果我发送带有额外参数的GET请求,Spring Boot无法识别我的 Controller :
http://localhost/idp/oauth/123/authorize?scope=public_profile
我需要准确接收第二个示例的请求(带有参数范围),但 Spring Boot 无法识别 Controller 并重定向到/error。
代码:
@Controller
@RequestMapping("/idp/oauth")
public class OAuthController {
@RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.GET)
public String authorizeGet(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable String clientId,
Model model) {
// ...
}
@RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.POST)
public String authorizePost(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable String clientId,
Model model) {
// ...
}
}
最佳答案
由于您传递了名为“scope”的额外参数,Spring 将在方法中搜索 @RequestParam
它找不到任何内容,因此出现错误
您需要修改您的方法以添加所有@RequestParam
如果可选字段不是必需的,您还可以添加 required = false
@RequestMapping(value = "/{clientId}/authorize", method = RequestMethod.GET)
public String authorizeGet(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable String clientId,
@RequestParam(value = "scope") String scope,
@RequestParam(required = false, value = "optionalParam") String optionalParam,
Model model) {
// ...
}
关于java - Spring Boot 无法识别带有发送请求参数的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58249280/