Java 在RepresentationModelAssembler中使用投影
在我的SpringBoot2.3应用程序中,我使用SpringDataREST、SpringHateOAS、SpringJPA、Hibernate等 在REST控制器中,我得到一个分页的实体列表,这些实体不是来自Jpa存储库,而是来自另一个源Java 在RepresentationModelAssembler中使用投影,java,spring,spring-data-rest,spring-hateoas,Java,Spring,Spring Data Rest,Spring Hateoas,在我的SpringBoot2.3应用程序中,我使用SpringDataREST、SpringHateOAS、SpringJPA、Hibernate等 在REST控制器中,我得到一个分页的实体列表,这些实体不是来自Jpa存储库,而是来自另一个源 @PostMapping(path = "/frames/searches") public ResponseEntity<?> search(@RequestBody List<Filter> fil
@PostMapping(path = "/frames/searches")
public ResponseEntity<?> search(@RequestBody List<Filter> filters, Pageable pageable) {
Page<Frame> pageResult = frameService.search(filters, null, pageable);
return new ResponseEntity<>(pagedResourcesAssembler.toModel(pageResult, frameResourceAssembler), HttpStatus.OK);
}
这很好,但我想返回该实体的投影。我创建了这个投影:
@Projection(name = "image", types = {Frame.class})
public interface FrameImageProjection {
ProductType getProductType();
String getSearchKey();
String getSku();
String getBarcode();
String getManufacturer();
String getImageUrl();
String getThumbUrl();
}
当然,它不是自动应用的。我看到了defaultextractprojector
,但它似乎需要存储库才能工作。
如何返回bean的投影,而不是返回包含所有字段的整个bean
@Projection(name = "image", types = {Frame.class})
public interface FrameImageProjection {
ProductType getProductType();
String getSearchKey();
String getSku();
String getBarcode();
String getManufacturer();
String getImageUrl();
String getThumbUrl();
}