springmvc 注解 RequestParam/RequestHeader/CookieValue

RequestParam注解:

示例:

@RequestMapping("/testRequestParam")
    public String testRequestParam(@RequestParam(name="username") String un,@RequestParam(name="age",required=false,defaultValue="0") int age) {
        System.out.println("testRequestParam: username="+un+" age="+age);
        return SUCCESS;
    }

RequestHeader注解:

示例:

@RequestMapping("/testRequestHeader")
    public String testRequestHeader(@RequestHeader(name="Accept-Language") String al) {
        System.out.println("testRequestHeader: al=" + al);
        return SUCCESS;
    }

CookieValue注解:

示例:

@RequestMapping("/testCookieValue")
    public String testCookieValue(@CookieValue(name="JSESSIONID") String sid) {
        System.out.println("testCookieValue:sid="+sid);
        return SUCCESS;
    }

 

posted on 2016-12-13 23:28  _故乡的原风景  阅读(449)  评论(0编辑  收藏  举报