Tag: spring data rest

如何使用Spring RestTemplate使用Page 响应

我正在使用spring数据(mongoDb),我有我的存储库: public interface StoriesRepository extends PagingAndSortingRepository {} 然后我有一个控制器: @RequestMapping(method = RequestMethod.GET) public ResponseEntity<Page> getStories(Pageable pageable) { Page stories = storiesRepository.findAll(pageable).map(StoryResponseMapper::toStoryResponse); return ResponseEntity.ok(stories); } 一切正常,但我不能使用RestTemplate getForEntity方法消耗我的端点: def entity = restTemplate.getForEntity(getLocalhost(“/story”), new TypeReference<Page>(){}.class) 我应该提供什么类来成功反序列化我的实体页面?

Spring Data Rest:未调用RepositoryEventHandler方法

我正在尝试将Spring Data REST文档中描述的RepositoryEventHandler添加到下面显示的REST存储库: @RepositoryRestResource(collectionResourceRel = “agents”, path = “/agents”) public interface AgentRepository extends CrudRepository { // no implementation required; Spring Data will create a concrete Repository } 我创建了一个AgentEventHandler: @Component @RepositoryEventHandler(Agent.class) public class AgentEventHandler { /** * Called before {@link Agent} is persisted * * @param agent */ @HandleBeforeSave public void handleBeforeSave(Agent agent) { System.out.println(“Saving Agent […]

Spring Data REST:覆盖控制器上的存储库方法

我有以下REST存储库,其实现由Spring在运行时生成。 @RepositoryRestResource public interface FooRepository extends CrudRepository { } 这意味着我将通过REST提供save(),find(),exists()和其他可用方法。 现在,我想覆盖其中一个方法; 例如,save()。 为此,我将创建一个暴露该方法的控制器,如下所示: @RepositoryRestController @RequestMapping(“/foo”) public class FooController { @Autowired FooService fooService; @RequestMapping(value = “/{fooId}”, method = RequestMethod.PUT) public void updateFoo(@PathVariable Long fooId) { fooService.updateProperly(fooId); } } 问题:如果我启用了这个控制器,那么Spring实现的所有其他方法都不再暴露。 因此,例如,我不能再对/ foo / 1执行GET请求 问题:是否有一种覆盖REST方法的方法,同时仍保留其他自动生成的Spring方法? 额外信息: 这个问题看起来非常相似: Spring Data Rest:RestController中的覆盖方法,具有相同的请求映射路径 …但我不想将路径更改为/ foo / 1 / save之类的东西 我想过使用@RepositoryEventHandler,但我不是很喜欢这个想法,因为我想把它封装在服务之下。 […]

spring-data-rest发布的自定义jpa存储库方法

我已经在jpa存储库中添加了一个自定义方法,详见http://docs.spring.io/spring-data/data-jpa/docs/1.0.x/reference/html/#repositories.custom-implementations 据我所知,当我使用spring-data-rest时,这个方法不会暴露。 有没有什么办法可以将它作为spring-data-rest生成的REST API的一部分发布(不用自己创建Spring MVC Controller)?

有选择地扩展Spring Data Rest响应中的关联

我有一个标准的Spring数据JPA和Spring数据Rest设置,它正确地返回关联作为正确资源的链接。 { “id”: 1, “version”: 2, “date”: “2011-11-22”, “description”: “XPTO”, “_links”: { “self”: { “href”: “http://localhost:8000/api/domain/1” }, “otherDomain”: { “href”: “http://localhost:8000/api/domain/1/otherDomain” } } } 但是在某些请求中,我希望扩展与“otherDomain”的关联(因此客户端不必执行N + 1个请求来获取完整数据)。 是否可以配置Spring Data Rest以这种方式处理响应?

在将应用程序迁移到Spring Boot之后使用Spring Data Rest时,我发现使用@Id的实体属性不再编组为JSON

这个问题与这个SO问题有关( Spring引导@ResponseBody没有序列化实体id )。 我观察到,在将应用程序迁移到Spring Boot并使用spring-boot-starter-data-rest依赖项后,我的实体@Id字段不再在生成的JSON中进行编组。 这是我的请求映射,在调试时,我可以看到数据在返回之前没有被更改,因此@Id属性稍后被剥离。 @RequestMapping(method = RequestMethod.GET, produces = {“application/json”}) public PagedResources receipts(Pageable pageable, PagedResourcesAssembler assembler) { Page receipts = receiptRepository.findByStorerAndCreatedDateGreaterThanEqual(“003845”, createdStartDate, pageable); PagedResources pagedResources = assembler.toResource(receipts, receiptResourceAssembler); return pagedResources; } 是否有一个设置允许我在生成的JSON中保留@Id字段,因为我的应用程序允许用户按该值进行搜索。 谢谢 :)

如何与Spring Data REST和JPA保持双向关系?

使用Spring Data REST。 如果您具有oneToMany或ManyToOne关系,则PUT操作在“非拥有”实体上返回200,但实际上不会保留已连接的资源。 示例实体。 @Entity(name = ‘author’) @ToString class AuthorEntity implements Author { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id String fullName @ManyToMany(mappedBy = ‘authors’) Set books } @Entity(name = ‘book’) @EqualsAndHashCode class BookEntity implements Book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id @Column(nullable = false) String title @Column(nullable = false) String isbn @Column(nullable = […]