如果mime-type为@RepositoryRestResource
,我如何指定application/json
个enpoints来响应?
@RequestMapping
GET-Request Accept : application/json
返回json
@RequestMapping(path="/path", headers ="Accept=application/json")
public String withHeader() {
return "{this:json}";
}
没有Accept : application/json
标头的GET-Request返回html
@RequestMapping("/path" )
public String withoutHeader() {
return "<html>...</html>";
}
答案 0 :(得分:1)
你无法开箱即用。您需要添加这样的配置
@Configuration
class RestMvcConfiguration {
@Bean
public RepositoryRestConfigurer repositoryRestConfigurer() {
return new RepositoryRestConfigurerAdapter() {
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.returnBodyOnUpdate("Accept=application/json")
config.returnBodyOnCreate("Accept=application/json");
}
};
}
}