SpringMVC使用@RequestMapping 注解为控制器指定可以处理哪些URL请求。

可以用于类定义以及方法定义:

  类定义:提供初步的请求映射信息。相对于WEB应用的根目录。

  方法处:提供进一步的细分映射信息。相对于类定义处的URL。若类定义处没有定义,则是相对于根目录。

  如:针对类设置了@RequestMapping("pathclass")注解,针对方法设置了@RequestMapping("method"),则最终调用到方法的url为pathclass/method,完整路径如http://localhost:8080/HelloWorld/pathclass/helloworld.

参考如下Controller测试代码:

package com.tiekui.springmvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("pathclass")
public class RequestMappingTest {
private static String SUCCESS="success"; @RequestMapping("helloworld")
public String hello(){
System.out.println("hello world from " + getClass());
return SUCCESS;
}
}

jsp中调用这个方法的参考代码如下,可以将以下代码加在HelloWorld工程中的index.jsp中。

<a href="pathclass/helloworld">Pathclass Hello world Test</a>

SpringMVC(三) RequestMapping修饰类的更多相关文章

  1. SpringMVC(二):RequestMapping修饰类、指定请求方式、请求参数或请求头、支持Ant路径

    @RequestMapping用来映射请求:RequestMapping可以修饰方法外,还可以修饰类 1)SpringMVC使用@RequestMapping注解为控制指定可以处理哪些URL请求: 2 ...

  2. SpringMVC 学习-异常处理 SimpleMappingExceptionResolver 类

    Spring3.0 对异常的处理方式总共有两种: 一种是使用 HandlerExceptionResolver 接口,并且 Spring 已经提供默认的实现类 SimpleMappingExcepti ...

  3. springMVC(1)---@RequestMapping详解

    @RequestMapping详解 RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上.用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径.这句话,太熟悉了.   ...

  4. SpringMVC中 -- @RequestMapping的作用及用法

    一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,相当于Servlet中在web.x ...

  5. SpringMVC 三种异常处理方式

    SpringMVC 三种异常处理方式 在 SpringMVC, SpringBoot 处理 web 请求时, 若遇到错误或者异常,返回给用户一个良好的错误信息比 Whitelabel Error Pa ...

  6. 【SpringMVC】---RequestMapping、Ant 路径、PathVariable 注解、HiddenHttpMethodFilter 过滤器、用 POJO 作为参数

    一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  7. Ajax Post提交事例及SpringMVC注解@RequestMapping取不到参数值解决办法

    var xmlHttp; //定义变量,用来创建xmlHttp对象 function ajaxfunction(url,onreadystatechangMethod,param){ // 创建xml ...

  8. 浅谈Kotlin(三):类

    浅谈Kotlin(一):简介及Android Studio中配置 浅谈Kotlin(二):基本类型.基本语法.代码风格 浅谈Kotlin(三):类 浅谈Kotlin(四):控制流 前言: 已经学习了前 ...

  9. C#_02.13_基础三_.NET类基础

    C#_02.13_基础三_.NET类基础 一.类概述: 类是一个能存储数据和功能并执行代码的数据结构,包含数据成员和函数成员.(有什么和能够干什么) 运行中的程序是一组相互作用的对象的集合. 二.为类 ...

随机推荐

  1. Android中Context的理解及使用(一)——Context的作用

    Context的作用:用来访问全局信息的接口,通过Context进行资源的访问. 1.Context获取字符串资源: public class MainActivity extends AppComp ...

  2. 预处理指令#pragma

    #pragma介绍 #pragma是一个预处理指令,pragma的中文意思是『编译指示』.它不是Objective-C中独有的东西(貌似在C/C++中使用比较多),最开始的设计初衷是为了保证代码在不同 ...

  3. Linux 平台GCC使用小结

    gcc -Wall [-I search_headfile_path] [-L search_lib_path] sourcefile -lNAME -o exe-name -Wall选项打开所有最常 ...

  4. SpringMVC上传文件的三种方式(转)

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

  5. jquery_DOM笔记4

    jQuery遍历函数: add()添加,可以是样式,字符串,元素,文本,js对象 andself() 指向匹配元素本身 chilidren() 匹配元素的所有子元素的匹配元素 closest() 从本 ...

  6. BZOJ 4184: shallot

    Description 在某时刻加入或删除一个点,问每个时刻的集合中能异或出来的最大值是多少. Sol 线段树+按时间分治+线性基. 按时间分治可以用 \(logn\) 的时间来换取不进行删除的操作. ...

  7. 键盘按钮keyCode大全

    字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L 76 U 85 3 ...

  8. asp:Repeater实例备忘

    1.前置部分 <asp:Repeater ID="rptPlanNo" runat="server" OnItemDataBound="rptP ...

  9. How do I get the path of the current executed file in Python?

    First, you need to import from inspect and os from inspect import getsourcefile from os.path import ...

  10. 用Xcode 安装ipa,查看程序资源文件夹

    Xcode中的Devices工具就能够提供以上2项功能,不需要安装其他第三方工具了,见下面的截图: