Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有余烬数据的Spring MVC CRUD控制器_Spring_Spring Mvc_Ember.js_Ember Data_Crud - Fatal编程技术网

带有余烬数据的Spring MVC CRUD控制器

带有余烬数据的Spring MVC CRUD控制器,spring,spring-mvc,ember.js,ember-data,crud,Spring,Spring Mvc,Ember.js,Ember Data,Crud,我在SpringMVCAPI中有一个CRUD控制器 这是我的创建方法: @Override @JsonView(ApiView.FormView.class) @RequestMapping(method = RequestMethod.POST, consumes = ApiMediaType.jsonContentType, produces = ApiMediaType.jsonContentType) public ApiResponse create(@

我在SpringMVCAPI中有一个CRUD控制器

这是我的创建方法:

    @Override
    @JsonView(ApiView.FormView.class)
    @RequestMapping(method = RequestMethod.POST, consumes = ApiMediaType.jsonContentType, produces = ApiMediaType.jsonContentType)
    public ApiResponse create(@RequestBody @Valid Entity entity, BindingResult result) {
        if (result.hasErrors()) return new ApiResponse(result.getAllErrors());
        service.add(entity);
        return new ApiResponse(entity);
    }
这很有效

如果我将这些数据发送到API,它就会工作

   {
        "email":"user@company.com",
        "password":"secret!",
        "firstName":"John",
        "lastName":"Doe",
        "title":"Mr."
    }
问题是我使用的是带有余烬数据的余烬JS。我的适配器正在发送以下数据:

{
   "data":{
      "attributes":{
         "email":"user@company.com",
         "firstName":"John",
         "lastName":"Doe",
         "title":"Mr.",
      },
      "type":"users"
   }
}
这不是my UserController在下面声明的创建方法中所期望的
@有效用户表单

公共ApiResponse创建(@RequestBody@Valid User form,BindingResult){}

如何将Ember发送给用户对象的数据转换为Spring应用程序


感谢并为我的英语感到抱歉。

您必须使用适合您的数据结构的MessageConverter和JacksonMapper

这里有一些教程


您必须使用适合您的数据结构的MessageConverter和JacksonMapper

这里有一些教程


您忘记了@ResponseBody注释

试试这个:

@Override
@JsonView(ApiView.FormView.class)
@RequestMapping(method = RequestMethod.POST, consumes = ApiMediaType.jsonContentType, produces = ApiMediaType.jsonContentType)
@ResponseBody    
public ApiResponse create(@RequestBody @Valid Entity entity, BindingResult result) {
    if (result.hasErrors()) return new ApiResponse(result.getAllErrors());
    service.add(entity);
    return new ApiResponse(entity);
}

您忘记了@ResponseBody注释

试试这个:

@Override
@JsonView(ApiView.FormView.class)
@RequestMapping(method = RequestMethod.POST, consumes = ApiMediaType.jsonContentType, produces = ApiMediaType.jsonContentType)
@ResponseBody    
public ApiResponse create(@RequestBody @Valid Entity entity, BindingResult result) {
    if (result.hasErrors()) return new ApiResponse(result.getAllErrors());
    service.add(entity);
    return new ApiResponse(entity);
}