1. @RequestMapping注解的作用位置

  @RequestMapping可以作用在类名上,也可以作用在方法上。 如果都有, 产生作用的路径是类名上的路径+方法上的路径。 比如EmployeeController的add方法,最终起作用的路径是 http://host:port/contextPath/employee/add

2. @RequestMapping注解的method参数

  method参数表示的HTTP请求的方式。常见的有GET,PUT,POST,DELETE等。若请求的方法与后台编写的方法不一致,会出现HTTP 405错误。

3. @PathVariable注解

  这是一种基于RESTFUL的注解。我们看到detail方法的@RequestMapping的value值/detail/{employeeId},参数中加入了一个@PathVariable employeeId。 这样起作用的路径就根据employee的Id,即每个员工都有独立的一个URI路径资源。 符合RESTFUL架构。

4. Controller的方法参数

  Controller的方法访问非常灵活。 比如Employee有id,name,age等属性。 只要我们在前台传入name为id,name,age这3个参数,并且接受的方法有一个Employee对象参数,SpringMVC会自动把3个注入到这个对象中。 还有其他一些Integer,Long参数等,SpringMVC会默认帮我们自动转化。 同时参数也可以丢入一些HttpServletRequest, HttpServletResponse, HttpServletSession对象,SpringMVC会自动帮我们注入。 这点非常方便。

5. 不带参数基于方法的@RequestMapping会被当然基于类的@RequestMapping所作用的地址的默认进入的方法

转自http://www.cnblogs.com/fangjian0423/p/springMVC-introduction.html#reference 部分片段。

大家可以学习学习,思路很清晰, 讲解的很到位,学习了! 感谢分享!

Springmvc常用注解的更多相关文章

  1. SpringMVC常用注解實例詳解3:@ResponseBody

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  2. SpringMVC常用注解實例詳解2:@ModelAttribute

    我的開發環境框架:        springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...

  3. springmvc常用注解与类型转换

    springmvc常用注解与类型转换 一:前置 spring -servlet.xml 注入 <!-- 启用spring mvc 注解 --> <context:annotation ...

  4. SpringMVC常用注解@Controller,@Service,@repository,@Component

    SpringMVC常用注解@Controller,@Service,@repository,@Component controller层使用@controller注解 @Controller 用于标记 ...

  5. 一 : springmvc常用注解

    springmvc常用注解详解1.@Controller在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层 ...

  6. 转:springmvc常用注解标签详解

    Spring5:@Autowired注解.@Resource注解和@Service注解 - IT·达人 - 博客园--这篇顺序渐进,讲得超级好--此人博客很不错http://www.cnblogs.c ...

  7. SpringMVC 常用注解 详解

    SpringMVC 常用注解 详解 SpringMVC 常用注解 1.@RequestMapping                                      路径映射 2.@Requ ...

  8. Spring 和 SpringMVC 常用注解和配置(@Autowired、@Resource、@Component、@Repository、@Service、@Controller的区别)

    Spring 常用注解 总结内容 一.Spring部分 1.声明bean的注解 2.注入bean的注解 3.java配置类相关注解 4.切面(AOP)相关注解 5.事务注解 6.@Bean的属性支持 ...

  9. SpringMVC常用注解,返回方式,路径匹配形式,验证

    常用注解元素 @Controller 标注在Bean的类定义处 @RequestMapping 真正让Bean具备 Spring MVC Controller 功能的是 @RequestMapping ...

  10. SpringMVC 常用注解

    本文参考了博客,具体请见:http://www.cnblogs.com/leskang/p/5445698.html Spring MVC的常用注解 1.@Controller @Controller ...

随机推荐

  1. Euclidean Space

    http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm

  2. php Hash Table(四) Hash Table添加和更新元素

    HashTable添加和更新的函数: 有4个主要的函数用于插入和更新HashTable的数据: int zend_hash_add(HashTable *ht, char *arKey, uint n ...

  3. DataGridview 绑定泛型List<T>

    .DataGridView数据绑定对比(DataTable与泛型List): 当DataGridView的DataSource是DataTable的时候,DataTable的数据改变时,DataGri ...

  4. string.replace正则表达式说明

    str.replace(reg,function($0,$1,$2...,index,str){ }); $0: 匹配模式的字符串$1...: 匹配模式子表达式的字符串,0个或多个,个数取决于子表达式 ...

  5. Page传回页面的值问题

  6. jquery取消选择select下拉框

    有三个select下拉框一个大类,两个小类隐藏,需要在选择大类的时候,小类显示同时清除另外的小类选择的项这需求有点儿.......... 下面是三个select: <select name=&q ...

  7. 如何判断PHP 是线程安全还是非线程安全的

    什么是线程安全与非线程安全? 线程安全就是在多线程环境下也不会出现数据不一致,而非线程安全就有可能出现数据不一致的情况. 线程安全由于要确保数据的一致性,所以对资源的读写进行了控制,换句话说增加了系统 ...

  8. 浙大PAT-1002

    1002. 写出这个数 (20) 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式 ...

  9. CSS-animations和transitions性能:浏览器到底做了什么?

    CSS animations 和 transitions 的性能:浏览器到底做了什么?(译) 原文地址:http://blogs.adobe.com/webplatform/2014/03/18/cs ...

  10. 前端性能利器——dynatrace ajax edition

    因为最近的工作跟性能分析有关系,所以写个小总结. 顺带推荐两个我常用的小工具: 1.文件对比工具beyond compare,非常好用,对比.修改很简单.当然我只是用的试用版本.google一下官网下 ...