Tag: spring hateoas

解析自定义控制器中的实体URI(Spring HATEOAS)

我有一个基于spring-data-rest的项目,它也有一些自定义端点。 为了发送POST数据,我正在使用json { “action”: “REMOVE”, “customer”: “http://localhost:8080/api/rest/customers/7” } 对于spring-data-rest来说这很好,但不适用于自定义控制器。 例如: public class Action { public ActionType action; public Customer customer; } @RestController public class ActionController(){ @Autowired private ActionService actionService; @RestController public class ActionController { @Autowired private ActionService actionService; @RequestMapping(value = “/customer/action”, method = RequestMethod.POST) public ResponseEntity doAction(@RequestBody Action action){ ActionType actionType = action.action; Customer customer […]

返回json意外,将“链接”拼写为“_links”并且结构不同,在Spring hateoas中

正如标题所说,我有一个资源对象Product扩展ResourceSupport 。 但是,我收到的回复有“_links”而不是“links”属性,并且具有不同的结构。 { “productId” : 1, “name” : “2”, “_links” : { “self” : { “href” : “http://localhost:8080/products/1” } } } 基于HATEOAS参考 ,预期是: { “productId” : 1, “name” : “2”, “links” : [ { “rel” : “self” “href” : “http://localhost:8080/products/1” } ] } 这是为了这个吗? 有没有办法改变它,或者如果不是结构那么就是“链接”? 我通过以下代码段添加了selfLink: product.add(linkTo(ProductController.class).slash(product.getProductId()).withSelfRel()); 我使用以下构建文件的spring boot: dependencies { compile (“org.springframework.boot:spring-boot-starter-data-rest”) { […]

Spring MVC 3:将Spring-Data页面作为JSON返回

我有一个用Spring-Data制作的数据访问层。 我现在正在创建一个Web应用程序。 这个控制器方法应该返回格式化为JSON的Spring-Data页面 。 这样的页面是一个列表,其中包含额外的分页信息,例如记录总量等等。 这是可能的,如果是的话怎么样? 与此直接相关,我可以定义属性名称的映射吗? 例如。 意思是我需要定义如何在JSON中命名分页信息属性(与页面不同)。 这可能吗?怎么样?