本文介绍了客户端发送的请求在语法上不正确().+ Spring,RESTClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用JSON对象使用Spring MVC.尝试从RESTClient发送JSON对象时,我得到
I am working with Spring MVC using JSON objects. while I am tring to send JSON Object from RESTClient, I am getting
这是我的控制器
ObjectMapper mapper=new ObjectMapper();
@RequestMapping(value = "/addTask", method = RequestMethod.GET)
public ModelAndView addTask(@RequestParam("json") String json) throws JsonParseException, JsonMappingException, IOException
{
System.out.println("Json object from REST : "+json);
Task task=(Task) mapper.readValue(json, Task);
service.addService(task);
return new ModelAndView("Result");
}
我的请求网址:http://localhost:8080/Prime/addTask
我的Json对象:
我也尝试在RESTClient中指定"Content-Type:application/json",但仍然出现相同的错误
Also i tried specifying "Content-Type: application/json" in RESTClient but still am getting the same error
推荐答案
尝试一下
更改
@RequestParam("json") String json
收件人
@RequestBody Task task
如果您对POST方法不感兴趣,可以尝试一下
If you are not interested in POST method you can try this
从
@RequestMapping(value = "/addTask", method = RequestMethod.GET)
public ModelAndView addTask(@RequestParam("json") String json)
到
@RequestMapping(value = "/addTask/{taskName}/{taskId}/{taskDesc}", method = RequestMethod.GET)
public ModelAndView addTask(@RequestParam("taskName") String taskName,
@RequestParam("taskId") String taskId,@RequestParam("taskDesc") String taskDesc)
并将您的URL更改为
http://localhost:8080/Prime/addTask/mytask/233/testDesc
这篇关于客户端发送的请求在语法上不正确().+ Spring,RESTClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!