spring mvc
http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html
18.2.1 URI Templates
///////////////////////////////////////////////////////////
RequestMethod.GET
///////////////////////////////////////////////////////////
@RequestMapping("/users/{userid}", method=RequestMethod.GET)
public String getUser(@PathVariable String userId) {
// implementation omitted...
}
@RequestMapping("/owners/{ownerId}", method=RequestMethod.GET)
public String findOwner(@PathVariable("ownerId") String theOwner, Model model) {
// implementation omitted
}
@RequestMapping("/owners/{ownerId}/pets/{petId}", method=RequestMethod.GET)
public String findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
Owner owner = ownerService.findOwner(ownderId);
Pet pet = owner.getPet(petId);
model.addAttribute("pet", pet);
return "displayPet";
}
@Controller
@RequestMapping("/owners/{ownerId}/**")
public class RelativePathUriTemplateController {
@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
// implementation omitted
}
}
method parameters that are decorated with the @PathVariable annotation can be of any simple type such as int, long, Date... Spring automatically converts to the appropriate type and throws a TypeMismatchException if the type is not correct.
///////////////////////////////////////////////////////////
RequestMethod.PUT
///////////////////////////////////////////////////////////
The @RequestBody method parameter annotation is used to indicate that a method parameter should be bound to the value of the HTTP request body. For example,
@RequestMapping(value = "/something", method = RequestMethod.PUT)
public void handle(@RequestBody String body, Writer writer) throws IOException {
writer.write(body);
}
** Mapping the request body with the @RequestBody annotation
18.2.2 Returning multiple representations
A RESTful architecture may expose multiple representations of a resource. There are two strategies for a client to inform the server of the representation it is interested in receiving.
To support multiple representations of a resource Spring provides the ContentNegotiatingViewResolver to resolve a view based on the file extension or Accept header of the HTTP request.
@Controller
public class ContentController {
private List<SampleContent> contentList = new ArrayList<SampleContent>();
@RequestMapping(value="/content", method=RequestMethod.GET)
public ModelAndView getContent() {
ModelAndView mav = new ModelAndView();
mav.setViewName("content");
mav.addObject("sampleContentList", contentList);
return mav;
}
}
18.2.3 Views
Several views were added in Spring 3 to help support creating RESTful services. They are:
*
AbstractAtomFeedView - return an Atom feed
*
AbstractRssFeedView - returns a RSS feed
*
MarshallingView - returns an XML representation using Spring's Object to XML mapping (OXM) functionality
[Note] Note
Available separately is the JacksonJsonView included as part of the Spring JavaScript project.
18.2.3.2 XML Marshalling View
18.2.4 HTTP Method Conversion
18.2.5 ETag support
这个先略过。
18.2.6 Exception Handling
感觉 spring3 的异常处理还是比较变态的,至少比 struts2 麻烦多了。刚又看到一篇文章:http://www.oschina.net/bbs/thread/13937,难道真的这么变态么?
不过这篇文章看起来还不赖:
http://blog.csdn.net/sinlff/archive/2010/09/09/5872724.aspx
其他:
有人说 springmvc 对静态资源的处理需要自己定制:
http://www.iteye.com/topic/743651
以上只是对spring 3 mvc 的一些粗略的了解。信息渠道主要是 spring3 的官方文档。具体应用方面的知识还非常欠缺。从网上找了些其他的例子:
http://www.iteye.com/topic/748006
http://ttaale.iteye.com/blog/761877
http://mxdba.iteye.com/blog/643168 (用户注册的例子)
这篇文章上有 spring3 rest 的文件上传和一个简单的demo,不错:
http://www.javabloger.com/page/9?author=1
百度贴吧上的一篇 demo:
http://tieba.baidu.com/f?kz=883344164
http://www.blogjava.net/pengo/archive/2010/07/03/325164.html
分享到:
相关推荐
SpringMVC学习笔记
springmvc学习笔记
springmvc 笔记
SpringMVC学习课堂笔记,记录基本的SpringMVC原理,基本用法和相关知识点。
SpringMVC-MyBatis学习笔记
Maven 构建SpringMVC项目学习笔记 一、背景介绍 二、构建工程 2.1、用maven插件构建项目框架 2.2、完善项目 2.3、将工程变成web工程 三、工程SpringMVC配置 3.1 赋予工程的springmvc特性 3.2、添加Maven依赖 四、...
个人学习spring框架时记录的笔记,纯手敲,SpringIOC+SpringMVC学习笔记,有兴趣的可以参考
SpringMVC构建REST接口的源代码
学习尚硅谷springMVC4的笔记,包含了springMVC所有主要功能,便于后续备忘及复习
SpringMVC学习笔记.md
学习SpringMVC的详细学习笔记,来自于动力节点王鹤老师的b站springmvc的课程课件,紧跟课程能够深入的了解并学习springmvc
springmvc个人学习笔记
传智 springmvc mybatis 燕青 笔记 教案 springmvc部分
springmvc: springmvc学习笔记-springmvc整合mybatis.zip
SpringMVC笔记.pdf
springmvc: springmvc学习笔记--springmvc注解开发.zip
springMVC笔记springMVC笔记springMVC笔记springMVC笔记
Spring SpringMVC JdbcTemplate
springmvc学习笔记.zip
SSM笔记-SpringMVC REST风格初识、RequestMapping/PathVariable/RequestParam/RequestHeader/CookieValue基本使用方法