报错就是这个,然后报错的信息再给点详细的
org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'numbers' for method parameter type String[] is not present at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValueInternal(RequestParamMethodArgumentResolver.java:218) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:193) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:114) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.29.jar:5.3.29] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.29.jar:5.3.29] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.29.jar:5.3.29] at javax.servlet.http.HttpServlet.service(HttpServlet.java:555) ~[tomcat-embed-core-9.0.78.jar:4.0.FR] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.29.jar:5.3.29] at javax.servlet.http.HttpServlet.service(HttpServlet.java:623) ~[tomcat-embed-core-9.0.78.jar:4.0.FR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209) ~[tomcat-embed-core-9.0.78.jar:9.0.78] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
前端代码
$('.permission-checkbox').change(function() { var selectedPermissions = $('.permission-checkbox:checked').map(function() { return this.value; // 获取复选框的值 }).get(); // 将jQuery对象转换为数组 console.log(selectedPermissions); // 在控制台打印选中的权限值 var id=document.getElementById("id").value; $.ajax({ url: urls+'/update_permission', type: 'POST', // 或者 'POST' 如果后端是用@PostMapping来接收 data: { id:id, numbers: selectedPermissions // 这是你的数组 }, dataType:"json", success: function(response) { console.log(response); // 这里处理你的响应 }, error: function(xhr, status, error) { console.error(error); // 错误处理 } }); });
后端代码
@RequestMapping("/update_permission") @ResponseBody public String updatePermission(@RequestParam("id") Integer id,@RequestParam("numbers") String[] numbers) { // numbers将会接收到一个String类型的数组,例如 ["3", "4", "5", "6", "8", "10"] // 你可以在这里处理数组数据 //@RequestParam("empIdArray[]") int[] empArr log.info("id:{},用户id:{}",id,numbers); return "6666"; }
解决方案
@RequestMapping("/update_permission") @ResponseBody public String updatePermission(@RequestParam("id") Integer id,@RequestParam("numbers[]") String[] numbers) { // numbers将会接收到一个String类型的数组,例如 ["3", "4", "5", "6", "8", "10"] // 你可以在这里处理数组数据 //@RequestParam("empIdArray[]") int[] empArr log.info("id:{},用户id:{}",id,numbers); return "6666"; }
标签:web,5.3,java,String,parameter,jar,29,org,type From: https://www.cnblogs.com/q202105271618/p/17818647.html