码迷,mamicode.com
首页 > 移动开发 > 详细

SpringMVC(三) RequestMapping修饰类

时间:2016-12-28 01:49:03      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:div   信息   test   ati   imp   static   tcl   gtest   cal   

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修饰类

标签:div   信息   test   ati   imp   static   tcl   gtest   cal   

原文地址:http://www.cnblogs.com/zhoutiekui/p/6227807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!