Tag: spring data rest

何时使用@RestController vs @RepositoryRestResource

我一直在研究如何在REST中使用Spring的各种示例。 我们的最终目标是Spring HATEOAS / HAL设置 我已经看到了在Spring中呈现REST的两种不同的方法 通过Controller中的@RestController 通过@RepositoryRestResource中的@RepositoryRestResource 我正在努力寻找的东西是为什么你会用另一个。 当试图实施最好的HAL? 我们的数据库后端是Neo4j。

我可以使自定义控制器镜像Spring-Data-Rest / Spring-Hateoas生成的类的格式吗?

我试图做一些我认为应该很简单的事情。 我有一个Question对象,用spring-boot,spring-data-rest和spring-hateoas来设置。 所有的基本工作正常。 我想添加一个自定义控制器返回一个List<Question>与格式完全相同的格式,我的Repository的/questions URL做,以便两者之间的响应是兼容的。 这是我的控制器: @Controller public class QuestionListController { @Autowired private QuestionRepository questionRepository; @Autowired private PagedResourcesAssembler<Question> pagedResourcesAssembler; @Autowired private QuestionResourceAssembler questionResourceAssembler; @RequestMapping( value = "/api/questions/filter", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody PagedResources<QuestionResource> filter( @RequestParam(value = "filter", required = false) String filter, Pageable p) { // Using queryDSL here […]

如何在Spring Boot中使用Springpipe理的Hibernate拦截器?

在Spring Boot中是否可以集成Springpipe理的Hibernate拦截器( http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch14.html )? 我正在使用Spring Data JPA和Spring Data REST,并且需要Hibernate拦截器来处理实体上特定字段的更新。 使用标准的JPA事件不可能获得旧的值,因此我认为我需要使用Hibernate拦截器。

禁用JSON中的超文本应用程序语言(HAL)?

在版本2.0.2.RELEASE中使用Spring Data REST和JPA。 如何禁用JSON中的超文本应用程序语言(HAL)? http://stateless.co/hal_specification.html 我已经尝试了很多东西,但无济于事。 例如,我已经将Accept和Content-type标头设置为“application / json”而不是“application / hal + json”,但是我仍然收到超链接的JSON内容。 例如,我想得到像这样的东西: { "name" : "Foo", "street" : "street Bar", "streetNumber" : 2, "streetLetter" : "b", "postCode" : "D-1253", "town" : "Munchen", "country" : "Germany", "phone" : "+34 4410122000", "vat" : "000000001", "employees" : 225, "sector" : { "description" : "Marketing", "average profit": […]

在Spring Data REST中发布@OneToMany子资源关联

目前我有一个使用Spring Data REST的Spring Boot应用程序。 我有一个域名实体Post有@OneToMany关系到另一个域名实体, Comment 。 这些类的结构如下: Post.java: @Entity public class Post { @Id @GeneratedValue private long id; private String author; private String content; private String title; @OneToMany private List<Comment> comments; // Standard getters and setters… } Comment.java: @Entity public class Comment { @Id @GeneratedValue private long id; private String author; private String content; […]

spring数据rest和Cors

我正在开发一个Rest接口和一个DART前端的Spring Boot应用程序。 XMLHttpRequest确实执行完全正确的OPTIONS请求。 在此之后,最后的GET(“/ products”)请求被发出并失败: 请求的资源上没有“Access-Control-Allow-Origin”标题。 原因' http:// localhost:63343 '因此不被允许访问。 经过一些debugging后,我发现了以下内容:AbstractHandlerMapping.corsConfiguration为除RepositoryRestHandlerMapping之外的所有子类填充。 在RepositoryRestHandlerMapping中,在创build时不存在/设置corsConfiguration,所以它不会被识别为corspath/资源。 =>没有附加CORS头文件 这可能是问题吗? 我该如何设置? configuration类: @Configuration public class RestConfiguration extends RepositoryRestMvcConfiguration { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowCredentials(false).allowedOrigins("*").allowedMethods("PUT", "POST", "GET", "OPTIONS", "DELETE").exposedHeaders("Authorization", "Content-Type"); } … } 我甚至试图设置Cors每个注释: @CrossOrigin( methods = RequestMethod.GET, allowCredentials = "false") public interface ProductRepository extends CrudRepository<Product, String> { } 原始请求标题: […]