问题描述
我有一个课程,里面有我想隐藏的细节.但我也需要得到它.所以我写了一个Projection
.但它不能正常工作.
I've a Class with details I want to hide. But I need to get it too. So I wrote a Projection
. But it doesn't work as it should.
我正在编写学校 <> 教师 (等等) 模型.
I'm writing School <> Teacher (and so on) model.
public class School{//...
有一个Set
.
从主要"路径(当然是学校)不应看到此集合.
This set shouldn't be visible from the 'main' path (which is School of course).
所以这是Projection
:
@Projection(name = "noTeacher", types = {School.class})
public interface SchoolNoTeacher extends ProjectionModel {
String getName();
String getSkz();
}
没有getTeachers()
!
这是我的 Repository
@RepositoryRestResource(path = "school", excerptProjection = SchoolNoTeacher.class)
public interface SchoolRepository extends PagingAndSortingRepository<School, Long> {//...
但我想自己处理其余路径.所以我也有一个控制器.
But I want to handle the rest path myself. So I've a controller too.
@RestController
@RequestMapping(ScoolModel.api + "/school")
public class SchoolRestController {//...
并且投影不起作用.有什么办法解决吗?
And the Projection is not working. Any way to fix it?
推荐答案
不要同时使用 @RestController
和 @RepositoryRestResource
.对于 Spring Data Rest,RepositoryRestResource 本质上是一个 Controller 和一个 Repository 组合在一起以生成 HATEOAS 服务端点.
Don't use a @RestController
and a @RepositoryRestResource
together. With Spring Data Rest, The RepositoryRestResource is essentially a Controller and a Repository combined together to produce a HATEOAS service endpoint.
如果您需要自定义基本 URI,请参阅此答案.
If you need to customize your base URI, please refer to this answer.
这篇关于带有 RestController 的 Spring Boot 投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!