Spring 3支持RESTful API/APP配置示例

2014-11-24 02:53:03 · 作者: · 浏览: 1

支持APP&API模式的RESTful配置示例
XML示例:
… default-autowire="byName" >


































xml, 需另外下载(http://xstream.codehaus.org/download.html),可比JAXB套件易用哦 -- >






2. 支持API模式的RESTful配置特例
Spring 3 Servlet + HttpMessageConverter + Annotation
– StringHttpMessageConverter: Text converter
– FormHttpMessageConverter : Form converter (application/x-www-form-urlencoded , ampped to MultiValueMap)
– MarshallingHttpMessageConverter: XML converter(marshaller)
– MappingJacksonHttpMessageConverter: JSON converter(via Jackson’s ObjectMapper
– AtomFeedHttpMessageConverter: ATOM converter(via ROME’s Feed API)
– RssChannelHttpMessageConverter : RSS converter(via ROME’s Feed API)
XML示例:










<
/bean>








com.company.project.bean.EntityA
com.company.project.bean.EntityB






控制器代码示例:
@RequestMapping(method=RequestMethod.GET, value="/emp/{id}", headers="Accept=application/json")
public @ResponseBody EntityA getEntityA(@PathVariable String id) { … return EntityA;}

2. 支持APP模式的RESTful配置特例

Spring 3 Servlet + MVC + Annotation
– ContentNegotiatingViewResolver: Resource representation negotiation
– BeanNameViewResolver: Common view resolver based on bean name as spring-like.
– UrlBasedViewResolver: Spring MVC view same as former Spring version (JSP for text/html)
– InternalResourceViewResolver: Mostly like to UrlBasedViewResolver.
– MappingJacksonJsonView : JSON view
– MarshallingView : XML view (via XStreamMarshaller or Jaxb2Marshaller, etc)
XML配置示例:
http://www.springframework.org/schema/context” … default-autowire="byName"































http://xstream.codehaus.org/download.html) -->







控制器代码示例:
@PATH(“/{id}”)
public ModelAndView show(@PathVariable java.lang.Integer id) throws Exception {
UserInfo userInfo = manger.get(id);
return new ModelAndView("/userinfo/edit","userInfo",userInfo);
作者“守望者的技术日记和六..”