DataForm posting values but on server its null

2019-09-08 17:51发布

问题:

using the DataForm object I found that its posting values correctly to server. Here is the screenshot

but on server I am getting null for these object. Here is my server side code

    @RequestMapping(method = POST, value = "/create", produces = "application/json")
    @ResponseBody
    public UIResponse createDS(@Validated @ModelAttribute(value = "dS") DSDto dSDto,
            BindingResult result) {
 //here dSDto.name and dSDto.description is null
}

回答1:

you have to add the @RequestBody annotation so Spring would convert the incoming JSON to a object from the post body .take a look at this stack overflow post @RequestBody and @ResponseBody annotations in Spring