spring-data-rest

Can Spring Data REST's QueryDSL integration be used to perform more complex queries?

雨燕双飞 提交于 2019-11-27 06:38:09
I'm currently building a REST API in which I want clients to easily filter on most properties of a specific entity. Using QueryDSL in combination with Spring Data REST ( an example by Oliver Gierke ) allows me to easily get to 90% of what I want by allowing clients to filter by combining query parameters which refer to properties (e.g. /users?firstName=Dennis&lastName=Laumen ). I can even customize the mapping between the query parameters and an entity's properties by implementing the QuerydslBinderCustomizer interface (e.g. for case insensitive searches or partial string matches). This is all

Why does RestTemplate not bind response representation to PagedResources?

强颜欢笑 提交于 2019-11-27 06:37:44
I am using spring-data-rest to expose entities as (paged) rest resources. Everything works fine, but when I request data via RestTemplate , I get an useless HATEOAS JSON (which I didn't ask for). The JSON seems to be a PagedResources. I could live with that, but the JSON isn't converted into an object correctly. There is no content inside. Repository: @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { List<Person> findByLastName(@Param("name") String name); } Client: public List<Person>

@NamedQuery override findAll in Spring Data Rest JpaRepository

女生的网名这么多〃 提交于 2019-11-27 06:04:48
问题 Is there a way to override the findAll query executed by Spring Data Rest? I need a way of filtering the results based on some specific criteria and it seems that using a @NamedQuery should be along the lines of what I'm looking for so I setup a test. @Entity @Table(name = "users") @NamedQueries({ @NamedQuery(name = "User.findAll", query="SELECT u FROM User u WHERE u.username = 'test'"), @NamedQuery(name = "User.findNameEqualsTest", query="SELECT u FROM User u WHERE u.username = 'test'") })

Spring Data Rest: RepositoryEventHandler methods not invoked

核能气质少年 提交于 2019-11-27 05:40:44
问题 I am trying to add a RepositoryEventHandler as described on Spring Data REST documentation to the REST repository shown below: @RepositoryRestResource(collectionResourceRel = "agents", path = "/agents") public interface AgentRepository extends CrudRepository<Agent, Long> { // no implementation required; Spring Data will create a concrete Repository } I created an AgentEventHandler: @Component @RepositoryEventHandler(Agent.class) public class AgentEventHandler { /** * Called before {@link

How to Log HttpRequest and HttpResponse in a file?

被刻印的时光 ゝ 提交于 2019-11-27 05:30:24
Can anyone explain any techniques to log HttpRequest and HttpResponse in a file. We are using Spring MVC/Spring Rest. What we want is to intercept the request before it is processed and log it. Same way intercept the response before it is sent and log it. Thanks a lot in advance. For logging the request Spring has the AbstractRequestLoggingFilter class (well actually one of the subclasses). This can be used to log the incoming request (before and after processing). Depending on the configuration this can include the payload, client information and full URL (including erquest parameters). All

How to work with DTO in Spring Data REST projects?

可紊 提交于 2019-11-27 04:07:58
Spring Data REST automates exposing only domain object. But most often we have to deal with Data Transfer Objects. So how to do this in SDR way? An approach of how to work with DTO in Spring Data REST projects The working example is here Entities Entities must implement the Identifiable interface. For example: @Entity public class Category implements Identifiable<Integer> { @Id @GeneratedValue private final Integer id; private final String name; @OneToMany private final Set<Product> products = new HashSet<>(); // skipped } @Entity public class Product implements Identifiable<Integer> { @Id

Can I make a custom controller mirror the formatting of Spring-Data-Rest / Spring-Hateoas generated classes?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 03:19:06
I'm trying to do something I think should be really simple. I have a Question object, setup with spring-boot, spring-data-rest and spring-hateoas. All the basics work fine. I would like to add a custom controller that returns a List<Question> in exactly the same format that a GET to my Repository 's /questions url does, so that the responses between the two are compatible. Here is my controller: @Controller public class QuestionListController { @Autowired private QuestionRepository questionRepository; @Autowired private PagedResourcesAssembler<Question> pagedResourcesAssembler; @Autowired

How to expose the resourceId with Spring Data Rest

℡╲_俬逩灬. 提交于 2019-11-27 03:19:02
问题 I had was to expose the primary key which is annotated with @Id in entity.the ID field is only visible on the resource path, but not on the JSON body. 回答1: You can configure this using the RepositoryRestConfigurerAdapter on entity level. @Configuration public class ExposeEntityIdRestConfiguration extends RepositoryRestConfigurerAdapter { @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(MyEntity.class); } } Be aware that using

Custom default headers for REST API only using Spring Data REST

瘦欲@ 提交于 2019-11-27 02:27:54
问题 I have a use case where my application hosts REST API and web application and we need to add custom header to REST APIs only. REST APIs are enabled through Spring Data REST. Typically we could use Servlet Filter to achieve this but we need code the logic of isolating requests to our REST API and add the custom headers. It would be nice if Spring Data REST API allows to add a default header to all the responses it generates. What are your thoughts? Don't say I am lazy :) 回答1: As Spring Data

Different JSON output when using custom json serializer in Spring Data Rest

被刻印的时光 ゝ 提交于 2019-11-27 02:22:59
问题 After adding a custom Jackson serializer based on the official documenation I've observed a slightly different json output format. This example is based on a fork of spring-restbucks. Extend org.springsource.restbucks.WebConfiguration from RepositoryRestMvcConfiguration and override configureJacksonObjectMapper : @Override protected void configureJacksonObjectMapper(ObjectMapper objectMapper) { final SimpleSerializers serializers = new SimpleSerializers(); serializers.addSerializer(Order