spring-data-rest

Spring Data REST URI vs. entity ID

爱⌒轻易说出口 提交于 2019-11-28 07:36:41
问题 Spring Data REST (and Spring HATEOAS in particular) decouples RESTful IDs (viz., URIs) from entity IDs, and I'm having trouble linking them back up when saving new objects. See the interesting discussion around this decoupling at https://github.com/SpringSource/spring-data-rest/issues/13. Suppose that a client app wants to create a new Ticket resource with an associated TicketCategory resource. I want to post the Ticket against a remote Spring Data REST endpoint. The Ticket doesn't yet have

Using @Version in spring-data project

房东的猫 提交于 2019-11-28 06:48:44
I've been working on a RESTful webservice with spring-data. A few days ago a special spring-data jpa REST framework was released . Now I noticed the ability to use @Version with this framework. Is this version generated by itself or do you need to do this manually? And is it possible to use @Version on it's own? (So that I don't have to change anything to my existing repositories/domain etc..) And do I need to do some extra configuration to make use of @Version? It's been a while since I posted this question but I've figured it out. I'll explain what I did so that it might be helpful to

How to disable the default exposure of Spring Data REST repositories?

送分小仙女□ 提交于 2019-11-28 06:24:05
I have a project that uses spring-data-rest, and has a dependency project that only uses Spring Data. Both projects have spring data repositories and use @EnableJpaRepositories to implement their repository interfaces, but I only want to export the repositories in the parent project. Here's my question: is there some way to configure Spring Data REST to only expose rest endpoints for resources in the parent project, without having to explicitly annotate every repository in the dependency project with @RepositoryRestResource(exported = false) ? If I can only do this with @RepositoryRestResource

Customizing Param Binding for QueryDSL Support

人走茶凉 提交于 2019-11-28 05:54:26
问题 I have a Spring Data Rest repository which utilises the QueryDSL support outlined here: https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling#spring-data-rest The default is to query all specified parameters using equals. A mechanism to override the param binding to something other than equals is given in the same article however it requires Java 8. https://spring.io/blog/2015/09/04/what-s-new-in-spring-data-release-gosling#querydsl-web-support Is there any clean way in

Desserialization of + (plus) in Spring Request Param

时间秒杀一切 提交于 2019-11-28 05:17:58
问题 I have a simple HTTP GET request like this: http://localhost:8080/search?page=0&size=20&sort=id,asc&description=1+3 And a RestController: @RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<List<TestEntity>> search(Pageable pageable, @RequestParam("description") String description) { Page<TestEntity> page = service.search(pageable, description); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page

Spring Data REST - Consume List of Entities, Java HATEOAS client

╄→尐↘猪︶ㄣ 提交于 2019-11-28 04:58:25
问题 I'm using Spring Data REST 2.5.1, Jackson 2.8.0, Spring Boot 1.3.6. I'm trying to retrieve a simple list of entities from my Repository via RestTemplate. I can hit the end point in a browser, and get the expected HAL data. Retrieving a single Entity works fine as below. These are all using the default SDR endpoints (e.g. localhost:{port}/myEntity). ResponseEntity<Resource<MyEntity>> responseEntity = new RestTemplate() .exchange( uri + "/1", HttpMethod.GET, HttpEntity.EMPTY, new

Spring Data Rest - Sort by multiple properties

时光毁灭记忆、已成空白 提交于 2019-11-28 04:38:40
I have an entity as below Class Person{ String id; String name; String numberOfHands; } With Spring Data Rest (Gosling Release Train), I'm able to specify localhost/Person?sort=name,asc for sorting name name ascending. Now, in a case where I need to sort by numberOfHands descending and name ascending. I'm able to specify localhost/Person?sort=numberOfHands,name,asc But, I'm not able to specify localhost/Person?sort=numberOfHands,desc,name,asc Is there a way to specify multiple sort order? Thanks! M. Deinum Solution (tl;dr) When wanting to sort on multiple fields you simply put the sort

Spring Data REST custom query integration

我的未来我决定 提交于 2019-11-28 04:12:09
I want to create a REST link for an Employee entity that will basically be a findByAllFields query. Of course this should be combined with Page and Sort . In order to do that I have implemented the following code: @Entity public class Employee extends Persistable<Long> { @Column private String firstName; @Column private String lastName; @Column private String age; @Column @Temporal(TemporalType.TIMESTAMP) private Date hiringDate; } So I would like to have lets say a query where I can do: http://localhost:8080/myApp/employees/search/all?firstName=me&lastName=self&ageFrom=20&ageTo=30

When to use @RestController vs @RepositoryRestResource

半城伤御伤魂 提交于 2019-11-28 03:26:23
I have been looking at various examples of how to use Spring with REST . Our end target is a Spring HATEOAS/HAL setup I have seen two distinct methods for rendering REST within Spring Via @RestController within a Controller Via @RepositoryRestResource within a Repository The thing I am struggling to find is why would you use one over the other. When trying to implement HAL which is best? Our database backend is Neo4j . zpontikas Ok, so the short story is that you want to use the @RepositoryRestResource since this creates a HATEOAS service with Spring JPA . As you can see here adding this

Spring Data Rest Pageable Child Collection

一曲冷凌霜 提交于 2019-11-28 02:51:43
问题 I have an @Entity called User. It has a Set of Changesets as follows: @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="user") private Set<Changeset> changesets = new HashSet<Changeset>(); I have a UserRepository: @Repository @RestResource(path = "users", rel = "users") public interface UserRepository extends JpaRepository<User, Long>{ } And a ChangesetRepository: @Repository @RestResource(path = "changesets", rel = "changesets") public interface ChangesetRepository extends