Java 我在使用ajax向控制器发送json数据时遇到问题
我在使用ajax向控制器发送json数据时遇到问题 我想我发送的数据很好,但我得到以下警告 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver-已解析[org.springframework.web.bind.MissingServletRequestParameterException:所需的int参数“bno”不存在] code:400 message:HTTP Status 400 – Bad Requesth1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}Java 我在使用ajax向控制器发送json数据时遇到问题,java,jquery,json,ajax,spring,Java,Jquery,Json,Ajax,Spring,我在使用ajax向控制器发送json数据时遇到问题 我想我发送的数据很好,但我得到以下警告 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver-已解析[org.springframework.web.bind.MissingServletRequestParameterException:所需的int参数“bno”不存在] code:400 message:HTTP Status 400 – Ba
HTTP Status 400 – Bad Request
Type Status ReportMessage Required int parameter 'bno' is not presentDescription The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).Apache Tomcat/8.5.34
还有我的控制器 @RequestMapping(value="/{uid}/{cno}", method=RequestMethod.DELETE)
public void deletecmt(@PathVariable int cno ,@PathVariable String uid,@RequestParam int bno
,@AuthenticationPrincipal SecurityCustomUser securityCustomUser) throws Exception{
}
和请求有效载荷
{"bno":14}
我不知道怎么了。
怎么了?{bno:bno}在请求主体中。因此,您的控制器方法应该是@RequestBody int bno@RequestParam用于servlet请求参数。i、 e:/uid/cno?bno=14
参考差异:在Spring World中,请求有效负载应对应于@RequestBody,e.x:
public SomethingElse updateValue(@RequestBody Something value) {
// ...
}
什么地方有什么东西
要使用@RequestParam,请参阅:
$.ajax在DELETE body中发送数据属性,而不是查询字符串Aha!多亏了你,我才知道两者的区别。谢谢
public SomethingElse updateValue(@RequestBody Something value) {
// ...
}