做练习时,遇到个错误,记一下
问题
java.lang.IllegalArgumentException: Invalid character found in the request target [/expert/deleteExpert?idList[]=10&idList[]=11]. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:490) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:261) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597) [tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.41.jar:9.0.41]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
错误做法
controller里
@RequestMapping(value = "/deleteExpert",method = RequestMethod.DELETE)
public void deleteExpert(@RequestParam("idList") List<Integer> idList){
expertService.deleteExpert(idList);
}
前端vue
delExpert: { url: '/expert/deleteExpert', method: 'delete' },
错误页面
改正之后
controller 把 RequestParam 改成 PathVariable
@RequestMapping(value = "/deleteExpert/{idList}",method = RequestMethod.DELETE)
public void deleteExpert(@PathVariable("idList") List<Integer> idList){
expertService.deleteExpert(idList);
}
前端
delExpert: { url: '/expert/deleteExpert/:idList', method: 'delete' }
路径正确,删除成功