springmvc 中RequestMapping注解的使用
1、RequestMapping注解既可以修饰方法,又可以修饰类型,类型指定的url相对于web跟路径,而方法修饰的url相对于类url;
2、RequestMapping的几个属性:
value:用于指定url;
method:用于指定请求方式;
params:请求参数,支持简单的表达式,例子: params = {"username","age!=10"}表示请求参数中必须有username age不能等于10.
headers:请求头,支持简单表达式,例子:headers = {"Accept Language=zh-CN,zh;q=0.8"}表示Accept Lanuage必须等于这个否则无法找到链接
这些参数用于更加精确指定请求。
3、RequestMapping注解支持ant类型通配符:
?:表示一个字符;
*:表示任意多个字符
**:匹配多层路径
例如:RequestMapping("testAnt/*/abc") 表示 /testAnt/sndbsbhds(任意多个字符)/abc
测试代码示例:
/**
* 四个属性用于指定更加详细的url headers = { "Accept-Language=zh-CN,zh;q=0.8,en;q=0.6" }
* "username",
*
* @return
*/
@RequestMapping(value = "/helloworld", method = RequestMethod.GET, params = {
"username", "age!=10" }, headers = { "Accept-Language=zh-CN,zh;q=0.8,en;q=0.6" })
public String hello() {
System.out.println("hello");
return SUCCESS;
} @RequestMapping(value = "/helloworld/*/abc", method = RequestMethod.GET)
public String hello1() {
System.out.println("hello");
return SUCCESS;
}
请求:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>welcome page</title>
</head>
<body>
<a href="test/helloworld?username=&age=11">Hello World</a>
<br>
<br>
<a href="test/helloworld/adaf/abc">test Ant</a>
</body>
</html>
springmvc 中RequestMapping注解的使用的更多相关文章
- SSM-SpringMVC-14:SpringMVC中大话注解式开发基础--呕心沥血版
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 注解的基础我不再多啰嗦,百度一搜很多,很详细啊,我就讲一下SpringMVC中的注解入门 通过注解的方式定义 ...
- SpringMVC 中 @ControllerAdvice 注解
SpringMVC 中 @ControllerAdvice 注解 1.@ControllerAdvice 1.1 全局异常处理 1.2 全局数据绑定 1.3 全局数据预处理 原文地址: 江南一点雨:S ...
- springmvc中RequestMapping的解析
在研究源码的时候,我们应该从最高层来看,所以我们先看这个接口的定义: package org.springframework.web.servlet; import javax.servlet.htt ...
- SpringMVC中 -- @RequestMapping的作用及用法
一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.x ...
- Spring|SpringMVC中的注解
文章目录 一.Spring注解 @Controller @ResuController @Service @Autowired @RequestMapping @RequestParam @Model ...
- 【SpringMVC】@RequestMapping注解
@RequestMapping注解的源码 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNT ...
- Springmvc中@RequestMapping 属性用法归纳
简介: @RequestMapping RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径. RequestM ...
- SpringMvc中@ModelAttribute注解的使用
一.绑定请求参数到指定对象 public String test1(@ModelAttribute("user") UserModel user) 只是此处多了一个注解@Model ...
- Spring MVC中@RequestMapping注解使用技巧(转)
@RequestMapping是Spring Web应用程序中最常被用到的注解之一.这个注解会将HTTP请求映射到MVC和REST控制器的处理方法上. 在这篇文章中,你将会看到@RequestMapp ...
随机推荐
- 20150911 for循环的用法以及小题目
for: for(初始条件,条件表达式,状态改变) { 循环体 } //100块钱,买2元一只的圆珠笔,3块钱一个的尺子,5元一个的铅笔盒,每样至少一个,正好花光,请问有多少中画法. //一张纸0.0 ...
- java_常用数据类型转换基础篇
一.java基本数据类型 1.java基本数据类型可分四类八中 第一类:整形:byte.short.int.long 第二类:浮点型:float(单精度) .double(双精度) 第三类:逻辑类型: ...
- Oracle数据库——基本操作
一.涉及内容 1.掌握Oracle 10g 相关服务的启动.停止. 2.熟练掌握数据库配置助手(DBA).企业管理器(OEM).SQL*Plus等工具的使用. 3.掌握使用STARTUP和SHUTDO ...
- Python报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
解决办法: 在报错的页面添加代码: import sys reload(sys) sys.setdefaultencoding('utf8')
- Struts2 - Action no cache
整了两天,终于找到一个比较满意的答案了:如何让action不被浏览器缓存 写一个interceptor: package com.my.interceptor; import javax.servle ...
- This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms
异常消息:This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms ...
- POJ #1042 Gone Fishing - WA by a DP solution. TODO
I used DP instead of Greedy. But got WA on PoJ, though it passed all web-searched cases. Maybe I hav ...
- 读书笔记:Ross:概率模型导论:方差和协方差
例2.34 考虑N个人,一些人赞同某个提议,另一些人反对.假定Np个人赞同,N-Np人反对,p未知.现在想要通过随机选取n个人调查他们的态度,并由此来估计总体中赞同这个提议的人员比例p. 设Xi=1表 ...
- bzoj4709 [jsoi2011]柠檬
Description Flute 很喜欢柠檬.它准备了一串用树枝串起来的贝壳,打算用一种魔法把贝壳变成柠檬.贝壳一共有 N (1 ≤ N ≤ 100,000) 只,按顺序串在树枝上.为了方便,我们 ...
- bzoj3743 Kamp
Description 一颗树n个点,n-1条边,经过每条边都要花费一定的时间,任意两个点都是联通的. 有K个人(分布在K个不同的点)要集中到一个点举行聚会. 聚会结束后需要一辆车从举行聚会的这点出发 ...