简体   繁体   English

@Projection 不工作

[英]@Projection not working

I've implemented a little sample project to illustrate the problem I have.我已经实施了一个小示例项目来说明我遇到的问题。 It's located here:它位于此处:

https://github.com/jvillane/spring-boot-hateoas-rest

What i'm trying to do is creating several @Projection 's of the same Entity:我想做的是创建同一个实体的多个@Projection

@Projection(name = "S", types = User.class)
public interface UserS {
    String getName();
}

@Projection(name = "M", types = User.class)
public interface UserM {
    String getName();
    String getDni();
}

@Projection(name = "L", types = User.class)
public interface UserL {
    String getName();
    String getDni();
    Country getCountry();
}

And using them to obtain more or less Entity information by calling (with and without quotes):并通过调用(带引号和不带引号)使用它们来获取或多或少的实体信息:

http://localhost:8080/api/users/1?projection=S
http://localhost:8080/api/users/1?projection=M
http://localhost:8080/api/users/1?projection=L

But it doesn't make a difference in the response, it's like it's using the default way to show the Entity info.但这对响应没有影响,就像它使用默认方式显示实体信息一样。

I don't know what i'm doing wrong.我不知道我做错了什么。 Any help is welcome.欢迎任何帮助。

See the following. 请参阅以下内容。 Is your Projection definition in the same package (or subpackage) as the corresponding entity. 您的Projection定义与相应实体位于同一包(或子包)中吗?

http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.projections

How does Spring Data REST finds projection definitions? Spring Data REST如何找到投影定义?

Any @Projection interface found in the same package as your entity definitions (or one of it's sub-packages) is registered. 在与您的实体定义(或其子包之一)相同的包中找到的任何@Projection接口都被注册。

You can manually register via RepositoryRestConfiguration.getProjectionConfiguration().addProjection(…) . 您可以通过RepositoryRestConfiguration.getProjectionConfiguration().addProjection(…)手动注册。

In either situation, the interface with your projection MUST have the @Projection annotation. 无论哪种情况,与您的投影的接口必须具有@Projection批注。

your class "entities", and your "interface" of Projection corresponding to your entitie must be in some package. for your case: entitie class UserS, and interface(Projection) USerS, must be in some package您的 class“实体”,以及与您的实体对应的 Projection 的“接口”必须位于某个 package。对于您的情况:实体 class UserS 和接口(投影)USerS,必须位于某个 package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM