使用这行代码生成链接时:
indexResource.add(linkTo(IndexController.class).withSelfRel());
生成此 JSON:
{
"links" : [ {
"rel" : "self",
"href" : "http://localhost:8080"
} ]
}
但是,Spring Data Rest 生成的资源链接会生成以下 JSON:
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/persons{?page,size,sort}",
"templated" : true
}
}
}
特别是,我想模仿 Spring Data Rest 制作的那个。我该怎么做?
我正在使用具有以下配置的 Spring Boot:
@Configuration
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
@ComponentScan
public class Application { ... }
保留或删除@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
似乎并没有改变任何东西。
我还有以下 gradle 依赖项:
compile "org.springframework.boot:spring-boot-starter-data-rest"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-jetty"
compile "org.springframework.data:spring-data-envers:0.2.0.RELEASE"
compile "org.hibernate:hibernate-envers:4.3.6.Final"
runtime "mysql:mysql-connector-java:5.1.32"
testCompile "junit:junit"