我已经配置了一个应用程序,它根据 url 末尾附加的内容返回 json 和 xml 视图。
按照:
http://pfelitti87.blogspot.co.uk/2012/07/rest-services-with-spring-3-xml-json.html
我想重新配置它,但只允许返回 xml。
不知道该怎么做,我所做的一切仍然返回 json,当没有附加到末尾时
@Bean(name = "viewResolver")
public ContentNegotiatingViewResolver viewResolver() {
ContentNegotiatingViewResolver contentNegotiatingViewResolver = new ContentNegotiatingViewResolver();
contentNegotiatingViewResolver.setOrder(1);
contentNegotiatingViewResolver.setFavorPathExtension(true);
contentNegotiatingViewResolver.setFavorParameter(true);
contentNegotiatingViewResolver.setIgnoreAcceptHeader(false);
Map<String, String> mediaTypes = new HashMap<String, String>();
mediaTypes.put("xml", "application/xml");
contentNegotiatingViewResolver.setMediaTypes(mediaTypes);
List<View> defaultViews = new ArrayList<View>();
defaultViews.add(xmlView());
contentNegotiatingViewResolver.setDefaultViews(defaultViews);
return contentNegotiatingViewResolver;
}
所以输出是这样的:
.../state.json error no jsp page json
.../state.xml works fine
.../state error no jsp page
我想要的是以下两个返回 xml 的 url
.../state
.../state.xml
上面的不行。。
这是控制器映射
@RequestMapping(value= "/{id}/{ref}/state", method = RequestMethod.GET)
public state getState(...) {...}