我创建了一个域模型productCategory
,其中一个字段已@DBRef
注释parentCategory
,如下所示:
@Document
public class ProductCategory{
@Id
private String id;
private String name;
@DBRef
private ProductCategory parentCategory;
setter.getter...
}
我的控制器很简单
@RequestMapping(value="/api/category", method=RequestMethod.POST)
public @ResponseBody ProductCategory addCategory(@RequestBody ProductCategory category) {
return category;
}
我尝试$ref
从 MongoDB 文档中注明,但我无法以服务器识别parentCategory
. 它总是会给我错误消息,例如
org.springframework.http.converter.HttpMessageNotReadableException
: 无法读取 JSON: 无法识别的字段“$ref
”
我通读了http://docs.spring.io/spring-data/data-mongodb/docs/1.5.0.RELEASE/reference/htmlsingle/#mapping-usage-references 和 spring 文档,但找不到任何相关内容.
我需要创建自定义HTTPMessageConverter
吗?