天天看点

[email protected]相关属性[email protected]相关属性

[email protected]相关属性

1.value属性

2.method属性

3.params属性

4.headers属性

5.ant风格地址

代码示例:

jsp界面:

<%--value属性--%>
<a href="${pageContext.request.contextPath}/testrequestmapping1" target="_blank" rel="external nofollow" >请求方式1</a><br>
<a href="${pageContext.request.contextPath}/testrequestmapping2" target="_blank" rel="external nofollow" >请求方式2</a>
<br>
<hr>

<%--method属性--%>
<form action="${pageContext.request.contextPath}/testMethod" method="post">
    <input type="submit" value="测试method">
</form>
<br>
<hr>

<%--param属性--%>
<a href="${pageContext.request.contextPath}/testParams?name=helong&age=10" target="_blank" rel="external nofollow" >请求方式3</a>
<br>
<hr>

<%--headers属性--%>
<a href="${pageContext.request.contextPath}/testheader" target="_blank" rel="external nofollow" >请求方式4</a>
<br>
<hr>


<%--ant地址风格--%>
<a href="${pageContext.request.contextPath}/testant/a" target="_blank" rel="external nofollow" >请求方式ant</a>
<br>
<hr>
           

前端控制器(Controller):

/*value属性
    * 实现多个请求访问一个方法里面
    * 如果只有一个请求方法时,可以省略大括号
    * */
    @RequestMapping(value={"testrequestmapping1","testrequestmapping2"})
    public String textrequest(){
        System.out.println("value属性");
        return "/second.action";
    }

    /*method属性
    * 用来设置映射的请求方式,值是requestMethod类的数组
    * 如果指定相应的请求,必须要满足相应的请求才能访问对应的方法
    * 如果没有设置method属性,默认都可以访问
    * 如果只有一个请求方法时,可以省略大括号
    * */
    @RequestMapping(value = {"testMethod"},method ={RequestMethod.GET,RequestMethod.POST} )
    public String testMethod(){
        System.out.println("testMethod");
        return "/second.jsp";
    }

    /*param属性
    * 必须设置对应的请求参数和请求值才能访问到对应的内容
    * */
    @RequestMapping(value="testParams",params = {"name=helong","age=10"})
    public String testParams(){
        System.out.println("testParams");
        return "/second.jsp";
    }


    /*headers属性
    * 发送的请求头必须要与设置的请求相同时,才能够访问到对应的方法
    * Host=localhost:8080,Host代表发送的地址
    * Referer=http://localhost:8080/requestmapping.jsp代表发送请求的界面
    * */
    @RequestMapping(value = "testheader",method={RequestMethod.GET},
            headers = {
                    "Host=localhost:8080",
                    "Referer=http://localhost:8080/requestmapping.jsp"
                }
            )
    public String testHeaders(){
        System.out.println("testHeaders");
        return "/second.jsp";
    }

    /*地址统配符
    * ‘?’:代表一个字符
    * ‘??’:代表两个字符
    * ‘*’:任意字符
    *  ‘**’:任意多级
    * */
    @RequestMapping("testant/?")
    public String testAnt(){
        System.out.println("testAnt");
        return "/second.jsp";
    }
           

继续阅读