Spring 无法读取HTTP消息:org.s.httradableexception:无法读取文档:无法识别的令牌';放置';:应为(';true';、';false';或';null';)
我正在SpringSTS中实现SpringDataJPA+Oracle。。。这是“邮递员中的示例应用程序,我得到了Get方法的响应200,但对于post和put,我猜无法从DB读取数据,并给出以下错误- 无法读取HTTP消息: org.springframework.http.converter.httpMessageNodeTableException: 无法读取文档:无法识别的标记“PUT”:应为 [来源]处的('true'、'false'或'null'): java.io。PushbackInputStream@1f1076e7;行:1,列:5];嵌套 异常为com.fasterxml.jackson.core.JsonParseException: 无法识别的标记“PUT”:应为(“true”、“false”或“null”) 在[来源:java.io。PushbackInputStream@1f1076e7;行:1,列:5] 控制器方法:Spring 无法读取HTTP消息:org.s.httradableexception:无法读取文档:无法识别的令牌';放置';:应为(';true';、';false';或';null';),spring,rest,spring-data-jpa,Spring,Rest,Spring Data Jpa,我正在SpringSTS中实现SpringDataJPA+Oracle。。。这是“邮递员中的示例应用程序,我得到了Get方法的响应200,但对于post和put,我猜无法从DB读取数据,并给出以下错误- 无法读取HTTP消息: org.springframework.http.converter.httpMessageNodeTableException: 无法读取文档:无法识别的标记“PUT”:应为 [来源]处的('true'、'false'或'null'): java.io。Pushback
@RequestMapping(value = "/all", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Hashtable<String, Person> gatAll() {
return personService.getAll();
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String updateUser(@RequestBody Person person, @PathVariable long id) {
try {
person.setId(id);
personService.save(person);
} catch (Exception ex) {
return "Error in Updating the user : " + ex.toString();
}
return "User successfully Updated";
}
@RequestMapping(value=“/all”,method=RequestMethod.GET,consumes=MediaType.APPLICATION\u JSON\u value,products=MediaType.APPLICATION\u JSON\u value)
公共哈希表gatAll(){
return personService.getAll();
}
@RequestMapping(value=“/update/{id}”,method=RequestMethod.PUT,products=MediaType.APPLICATION\u JSON\u value,consumes=MediaType.APPLICATION\u JSON\u value)
@应答器
公共字符串updateUser(@RequestBody Person,@PathVariable long id){
试一试{
person.setId(id);
个人服务。保存(个人);
}捕获(例外情况除外){
return“更新用户时出错:”+ex.toString();
}
返回“用户已成功更新”;
}
错误可能是由于您提供给控制器的数据格式造成的。您的控制器方法需要JSON字符串。
例如,在jQuery中,JSON.stringify()为您提供JSON字符串。
因此,我建议您在客户端确认这一点,从客户端将数据发送到此控制器
我在做一个项目时也遇到过类似的错误。我的客户端是用python编写的,它应该向我发送JSON字符串。所以,我不得不使用dumps()并成功了
@RequestMapping(value = "/all", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Hashtable<String, Person> gatAll() {
return personService.getAll();
}
@RequestMapping(value = "/update/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String updateUser(@RequestBody Person person, @PathVariable long id) {
try {
person.setId(id);
personService.save(person);
} catch (Exception ex) {
return "Error in Updating the user : " + ex.toString();
}
return "User successfully Updated";
}