【发布时间】:2014-11-26 05:21:46
【问题描述】:
我有一个与其他实体有多个双向多对一关联的类 Category-
public class Category implements Serializable {
@Id
@Column(name = "CATEGORY_ID", unique = true, nullable = false)
@TableGenerator(name = Category.TABLE_NAME, table = "LMC_GENERATED_KEYS", pkColumnName = "ID", valueColumnName = "LAST_VALUE", pkColumnValue = Category.TABLE_NAME, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = Category.TABLE_NAME)
private Long categoryId;
// bi-directional many-to-one association to LmcCategoryImage
@OneToOne(mappedBy = "categoryImage")
@JsonManagedReference
private CategoryImage categoryImage;
// bi-directional many-to-one association to LmcCategoryProductXref
@OneToMany(mappedBy = "categoryProductXref")
@JsonManagedReference
private Set<CategoryProductXref> categoryProductXrefs;
// bi-directional many-to-one association to LmcCategoryXref
@OneToMany(mappedBy = "categoryxref", fetch = FetchType.LAZY)
@JsonManagedReference
private Set<CategoryXref> categoryxrefs;
}
这已通过以下存储库公开为存储库。
public interface CategoryRepository extends PagingAndSortingRepository<Category, Long> {
}
此存储库生成以下 json-
{
"_links": {
"self": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories{?page,size,sort}",
"templated": true
}
},
"_embedded": {
"categories": [
{
"activeEndDate": "2014-11-25T04:40:52.000+0000",
"activeStartDate": "2014-11-25T04:40:37.000+0000",
"archived": false,
"createdBy": "SYSTEM",
"modifedBy": "SYSTEM",
"dateCreated": "2014-11-25T04:40:37.000+0000",
"dateModified": "2014-11-25T04:40:37.000+0000",
"description": "DESCRIPTION",
},
"categoryImage": null,
"categoryProductXrefs": [
],
"productFeatureds": [
],
"_links": {
"self": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001"
},
"categoryXrefs": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/categoryXrefs"
},
"parentCategory": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/parentCategory"
},
"categoryAttributes": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/categoryAttributes"
},
"productProductFeatured": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/productProductFeatured"
},
"categoryProductFeature": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/categoryProductFeature"
},
"categoryImage": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/categoryImage"
},
"categoryProductXref": {
"href": "http://localhost:8080/lmc-persistence/jpa/categories/10001/categoryProductXref"
}
}
}
]
},
"page": {
"size": 20,
"totalElements": 1,
"totalPages": 1,
"number": 0
}
在这个 json 中,所有 _link 都是自动创建的,因为我已经在这个实体中通过关系映射。
这些 url 已根据给定的属性名称生成为驼峰式大小写。有什么办法,我可以覆盖这些名称并给我自己的自定义名称,如 categoryImage 作为 categoryimg 和 categoryProductXref 作为 categoryproductxref
【问题讨论】:
标签: rest spring-data-rest