使用不带注解@Projection 的投影
Using projection without the annotation @Projection
情况
我从开发人员那里继承了一些代码,这些代码似乎使用了 spring.
的未记录的功能
具体来说,它与使用 @projection
功能有关,但实际上并未这样注释 interface
。
具体例子如下:
public interface DirType extends KeyValInterface {
@Value("#{target.id}") String getId();
@Value("#{target.code}") String getText();
}
根据官方文档,这应该不起作用,但确实如此。
public interface DirTypeRepository extends JpaRepository<ABDirType, Long> {
List<DirType> findAllSummarizedBy();
}
所以存储库的方法findAllSummarizedBy()
实际上是发送一个DirType
的列表。
它使用 @Value
注释进行映射,但没有 @Projection
注释。
Entity
class如下:
@Data @Entity @Table(name="dir_type") @AllArgsConstructor @NoArgsConstructor
public static class ABDirType {
private @Id @GeneratedValue Long id;
private String code;
}
问题
有没有人知道这个与 Projections
相关但未将界面注释为 @Projection
的未记录功能的更多信息?
这是否适用于所有版本,或者它是否是一个使用有风险的隐藏黑客?
在 Spring Data JPA(您似乎在此处使用)中,您可以简单地使用具有适当吸气剂的接口作为投影目标。
请参阅 the documentation(尤其是 "Example 62. Simple Projection")。
文档中似乎没有任何 @Projection
注释。
情况
我从开发人员那里继承了一些代码,这些代码似乎使用了 spring.
的未记录的功能具体来说,它与使用 @projection
功能有关,但实际上并未这样注释 interface
。
具体例子如下:
public interface DirType extends KeyValInterface {
@Value("#{target.id}") String getId();
@Value("#{target.code}") String getText();
}
根据官方文档,这应该不起作用,但确实如此。
public interface DirTypeRepository extends JpaRepository<ABDirType, Long> {
List<DirType> findAllSummarizedBy();
}
所以存储库的方法findAllSummarizedBy()
实际上是发送一个DirType
的列表。
它使用 @Value
注释进行映射,但没有 @Projection
注释。
Entity
class如下:
@Data @Entity @Table(name="dir_type") @AllArgsConstructor @NoArgsConstructor
public static class ABDirType {
private @Id @GeneratedValue Long id;
private String code;
}
问题
有没有人知道这个与 Projections
相关但未将界面注释为 @Projection
的未记录功能的更多信息?
这是否适用于所有版本,或者它是否是一个使用有风险的隐藏黑客?
在 Spring Data JPA(您似乎在此处使用)中,您可以简单地使用具有适当吸气剂的接口作为投影目标。
请参阅 the documentation(尤其是 "Example 62. Simple Projection")。
文档中似乎没有任何 @Projection
注释。