springmvc二: @RequestMapping
spring mvc 使用 @RequestMapping注解为控制器指定可以处理哪些URL请求.
@RequestMapping 不仅可以修饰方法,也可以修饰类.
类定义处:
提供初步的请求映射信息,相对于WEB应用的根目录.
方法定义处:
提供进一步的细分映射信息。相对于类定义处的URL。若类定义处未标注@RequestMapping,则方法出标记的URL相对于WEB应用的根目录。
如下: 请求的url就会变成 http://localhost:8083/springmvc-1/SpringMvc/TestMapping
package com.atChina.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@RequestMapping("/SpringMvc")
@Controller
public class RequestMapperingTest {@RequestMapping("/TestMapping")public String TestMapping(){System.out.println("TestMapping");return "success";}
}
DispatcherServlet截获请求后,就通过控制器上@RequestMapping提供的映射信息确定请求所对应的处理方法。
@RequestMapping 的value,mthod, params,heads属性可以让请求映射更精确化
ge
package com.atChina.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@RequestMapping("/SpringMvc")
@Controller
public class RequestMapperingTest {// 只能映射 POST方法的请求@RequestMapping(value="/testMethod", method=RequestMethod.POST)public String TestMethod(){System.out.println("testMethod");return "success";}}
@RequestMapping支持ant风格
package com.atChina.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;@RequestMapping("/SpringMvc")
@Controller
public class RequestMapperingTest {@RequestMapping("/TestAntPath/*/abc")public String TestAntPath(){System.out.println("TestAntPath");return "success";}}
@PathVariable映射URL绑定的占位符
springmvc二: @RequestMapping相关推荐
- SpringMVC 学习笔记(二) @RequestMapping、@PathVariable等注解
版权声明:本文为博主原创文章,博客地址:http://blog.csdn.net/a67474506?viewmode=contents 1.1. @RequestMapping映射请求 Spring ...
- (续)SSM整合之springmvc笔记(@RequestMapping注解)(P124-130)
目录 @RequestMapping注解 一.准备工作 1 新建spring_mvc_demo com.atguigu 2. 导入依赖 3 .添加web模板 4 . 在web.xml里面进行进行 ...
- springmvc注解@RequestMapping
springmvc注解@RequestMapping 1.处理器.controller的url 2)跟路径+子路径. 3)限定提交方法 @RequestMapping的属性method: 1.Requ ...
- SpringMVC中 -- @RequestMapping的作用及用法
一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.x ...
- SpringMVC(二)——转发和重定向、处理前端请求的数据(普通字符串/对象)
文章目录 1. 转发和重定向 2. 处理前端请求的数据 2.1 普通字符串 2.2 对象 1. 转发和重定向 转发:url不会发生变化 (查询前端固定模板的数据) @RequestMapping(&q ...
- SpringMVC(十一) RequestMapping获取Cookie值
可以在控制器方法中使用类似@CookieValue("JSESSIONID") String sessionID的方式,来获取请求中的Cookie的值. 样例控制器代码 packa ...
- SpringMVC(二)高级
高级参数绑定 1.1. 绑定数组 1.1.1. 需求 在商品列表页面选中多个商品,然后删除. 1.1.2. 需求分析 功能要求商品列表页面中的每个商品前有一个checkbok,选中多个商品后点击删除按 ...
- SpringMVC之@RequestMapping注解及其衍生注解详解
@RequestMapping是springmvc核心注解之一,主要作用是建立请求URL与请求方法之间的映射关系,每当客户端有请求发过来,就根据请求URL找到对应的方法反射进行调用. //该注解可以作 ...
- Spring-mvc设置@RequestMapping标签更改返回头及@RequestMapping简述
1. 引子:设置返回头 2. 简述 3. value 4. method 5. consumes/produces 6. params 7. headers 1. 引子:设置返回头 返回JSON内容时 ...
最新文章
- javax.servlet.ServletException: Servlet[springmvc]的Servlet.init()引发异常
- DropDownList控件
- Spring任务调度之Spring-Task
- python 如何定义字典_python dict如何定义
- android访问重定向地址,如何从android中重定向url加载图像(示例代码)
- Springboot Failed to parse configuration class [x]; nested exception
- SQLServer扩展存储过程
- python读音发音-python3 - 文本读音器
- POP3协议学习笔记
- etymon word flower bee apiary forget out~1
- 组概念_【收藏】学习质谱一定要知道的6组概念
- HTML当当图书馆作业介绍
- 面试——测试基础理论
- 首月流水2.39亿美元,《原神》的发行策略是什么?
- RSA加密应用常见缺陷的原理与实践
- Redis学习之srem命令
- 二分法求三次方根代码
- python求15的因数_python学习第15期
- 如何在win7下装ubuntu(硬盘版安装)
- 前端:时间( ISO)标准时间转换为时间戳