以 1 对 n 基数保存对象

Saving object with 1-to-n cardinality

我目前正在使用 JHipster v2.23。我必须自定义用户 class 以添加一些属性。一切都很好,直到我不得不为其添加 1 对 n 关系。

public class User extends AbstractAuditingEntity implements Serializable {
    // attributes...
    private Set<MyClass> myClass = new HashSet<>();
    // gets/sets
}

从视图的角度来看,我对注册表单进行了必要的更新,包括处理一对多关系所需的代码。但是,当我尝试将它 post 设置为 /api/register 时,出现以下错误(只需在 register.controller.js 中设置 $scope.registerAccount.myClass=[] 就可以重现它,因为当注册表为 posted 时,此数组将在 json 中发送:

"The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."

我读过一些关于这个问题的post:

  1. Spring MVC + JSON = 406 Not Acceptable
  2. spring mvc not returning json content - error 406
  3. Spring 3.x JSON status 406 "characteristics not acceptable according to the request "accept" headers ()"

我尝试了几种方法:

  1. 正在添加@EnableWebMvc,但我开始看到一些映射错误;
  2. 添加一些 jackson 依赖项,但没有帮助;

我想知道 JHipster 代码是否真的没有准备好处理这种情况,因为它似乎并不罕见。

有没有人遇到过这个问题? 关于如何使用 JHipster 解决此问题的任何提示?

提前致谢。

好的。我设法修好了。我添加了 "header parameter to accept all content-types":

@RequestMapping(value = "/register",
        method = RequestMethod.POST,
        headers="Accept=*/*",
        produces = MediaType.TEXT_PLAIN_VALUE)
@Timed
public ResponseEntity<?> registerAccount(@Valid @RequestBody UserDTO userDTO, HttpServletRequest request) {
    // ...
}

我很确定将 headers 设置为 "application/json" 应该可以,但我还没有机会测试它。