我在swagger中运行API时出现以下错误:
2023-09-14 14:38:07.208 WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Error = [Missing Required Field(s). Please refer to the API documentation] Exception = [Required request parameter 'documentIds' for method parameter type List is not present]
2023-09-14 14:38:07.217 WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Exception
org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'documentIds' for method parameter type List is not present
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.27.jar:5.3.27]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.27.jar:5.3.27]
下面是我的控制器代码和请求数据,我从swagger传递
@RequestMapping(method = {RequestMethod.POST}, value = "/updateDocumentIds", headers = "Accept=application/json")
@ResponseBody
public ActionResult updateDocumentIds(@CustomRequestParam(value = "documentIds",required = true) List<String> documentIds, @RequestParam(value = "route") Boolean route) throws Exception {
ActionResult actionResult = new ActionResult();
//runs service method
return actionResult;
}
傲慢的要求
任何帮助感谢!
2条答案
按热度按时间6qfn3psc1#
您遇到的错误消息
表示您发送的Swagger请求不包含所需的
documentIds
参数。你需要像这样修正你的斯瓦格请求
0yycz8jy2#
我们可以使用
@Requestbody
注解来代替@CustomRequestParam
,这将把数据复制到列表中。