Spring REST service: retrieving JSON from Request

后端 未结 11 673
甜味超标
甜味超标 2020-11-27 04:35

I am building a REST service on Spring 3.1. I am using @EnableWebMVC annotation for that. Since my service will only be accepting JSON requests, I would also like to dump th

11条回答
  •  失恋的感觉
    2020-11-27 05:03

    Hey can you try with this:

    @RequestMapping(method = RequestMethod.POST, consumes="application/json", produces="application/json", value = "/employee")
    @ResponseBody
    public String updateEntity(@RequestBody Employee emp) {
        // Do some DB Stuff. Anyway, the control flow does not reach this place.
        return "Employee " + emp.getName() + " updated successfully!";
    }
    

    Here: it you proving URI with the '/' it allows all the operations to perform. such as get post update and delete with same URI value.

提交回复
热议问题