Spring @RequestMapping的用法
2015-03-19 17:32
369 查看
Spring @RequestMapping用来处理请求映射的注解,可以用在类或者方法上;当被用在类上时,类中所有相应请求的方法都以该路径作为父路径。
RequestMapping注解有六个属性:
1、value:指定请求的实际地址,指定的地址可以是URI Template 模式。
2、method:指定请求的method类型,包括GET、POST、PUT、DELETE等。
3、consumes:指定处理请求的提交内容类型(Content-Type),例如application/json, multipart/form-data。
4、produces:指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回。
5、params:指定request中必须包含某些参数值,才让该方法处理。
6、headers:指定request中必须包含某些指定的header值,才能让该方法处理请求。
示例:
@Controller
@RequestMapping("/api/sign")
public class SignApi {
@ResponseBody
@RequestMapping(value = "/sign", method = RequestMethod.POST, produces = "application/json;charset=UTF-8", consumes = "multipart/form-data")
public SignResult sign(HttpServletRequest request,
@RequestParam(value = "json") String json,
@ApiParam(name = "image") @RequestParam(value = "image") MultipartFile signature) {
......//代码
}
}
value的uri值为以下三类:
A) 可以指定为普通的具体值;
B) 可以指定为含有某变量的一类值(URI Template Patterns with Path Variables);
C) 可以指定为含正则表达式的一类值( URI Template Patterns with Regular Expressions)
参考文档:
http://blog.csdn.net/walkerjong/article/details/7994326 http://docs.spring.io/spring/docs/4.2.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#mvc-ann-methods
RequestMapping注解有六个属性:
1、value:指定请求的实际地址,指定的地址可以是URI Template 模式。
2、method:指定请求的method类型,包括GET、POST、PUT、DELETE等。
3、consumes:指定处理请求的提交内容类型(Content-Type),例如application/json, multipart/form-data。
4、produces:指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回。
5、params:指定request中必须包含某些参数值,才让该方法处理。
6、headers:指定request中必须包含某些指定的header值,才能让该方法处理请求。
示例:
@Controller
@RequestMapping("/api/sign")
public class SignApi {
@ResponseBody
@RequestMapping(value = "/sign", method = RequestMethod.POST, produces = "application/json;charset=UTF-8", consumes = "multipart/form-data")
public SignResult sign(HttpServletRequest request,
@RequestParam(value = "json") String json,
@ApiParam(name = "image") @RequestParam(value = "image") MultipartFile signature) {
......//代码
}
}
value的uri值为以下三类:
A) 可以指定为普通的具体值;
B) 可以指定为含有某变量的一类值(URI Template Patterns with Path Variables);
C) 可以指定为含正则表达式的一类值( URI Template Patterns with Regular Expressions)
参考文档:
http://blog.csdn.net/walkerjong/article/details/7994326 http://docs.spring.io/spring/docs/4.2.0.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#mvc-ann-methods
相关文章推荐
- spring 3.2 @Autowired 和@RequestMapping的理解和用法
- spring boot中的@RequestMapping注解的用法
- Spring @RequestMapping
- spring No mapping found for HTTP request with URI
- spring-mvc @RequestMapping 多个url映射到一个方法
- @RequestMapping 用法详解之地址映射
- Spring 的MVC @RequestMapping
- springMVC @RequestMapping
- No mapping found for HTTP request with URI [/login.do] in DispatcherServlet with name 'spring'
- @RequestMapping 用法详解之地址映射
- @RequestMapping 用法详解之地址映射
- Spring MVC No mapping found for HTTP request with URI
- Spring mvc中@RequestMapping…
- No mapping found for HTTP request with URI [/spring/WEB-INF/page/index.jsp] in DispatcherServlet with name 'spring'
- springMVC No mapping found for HTTP request with URI
- Spring 的MVC @RequestMapping
- spring mvc No mapping found for HTTP request with URI [] in DispatcherServlet
- @RequestMapping 相关 spring
- spring3 的restful API RequestMapping介绍
- @Controller以及 @RequestMapping("/loginServlet/LoginServlet")的用法