1. 程式人生 > >springmvc_1_使用 @RequestMapping 對映請求&對映請求引數 & 請求頭

springmvc_1_使用 @RequestMapping 對映請求&對映請求引數 & 請求頭

/**
     * 
     * @return
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET ,headers = {"Accept=text/html"})
    public String hello(){
        System.out.println("springmvc hello!");
        return "springmvc/RequestMappingTest/success";
    }

    @RequestMapping(value = "/ant/user?"
) public String AntTest( HttpServletRequest request, Model uiModel ){ String url = request.getRequestURI(); uiModel.addAttribute("url", url); return "springmvc/RequestMappingTest/ant"; } @RequestMapping(value = "/ant/user??") public
String AntTest3( HttpServletRequest request, Model uiModel ){ String url = request.getRequestURI(); uiModel.addAttribute("url", url); return "springmvc/RequestMappingTest/ant"; } @RequestMapping(value = "/ant/yy/*/user") public String AntTest1
( HttpServletRequest request, Model uiModel ){ String url = request.getRequestURI(); uiModel.addAttribute("url", url); return "springmvc/RequestMappingTest/ant"; } /** * http://127.0.0.1:8080/laweyecloud/springmvc/ant/111/123123/user */ @RequestMapping(value = "/ant/**/user") public String AntTest2( HttpServletRequest request, Model uiModel ){ String url = request.getRequestURI(); uiModel.addAttribute("url", url); return "springmvc/RequestMappingTest/ant"; } /** * http://127.0.0.1:8080/laweyecloud/springmvc/PathVariable/{hgh} * @param value * @param uiModel * @return */ @RequestMapping(value = "/PathVariable/{value}") public String PathVariableTest(@PathVariable("value") String value, Model uiModel){ uiModel.addAttribute("value", value); return "springmvc/PathVariable/PathVariable"; } /** * http://127.0.0.1:8080/laweyecloud/springmvc/RequestParam?name=hgh&password=123 * @param name * @param password * @param uiModel * @return */ @RequestMapping(value = "RequestParam") public String RequestParamTest( @RequestParam(value = "name",required = true) String name, @RequestParam(value = "password" , required = false) String password, Model uiModel ){ uiModel.addAttribute("name", name); uiModel.addAttribute("password", password); return "springmvc/RequestParam/RequestParam"; } @RequestMapping(value = "RequestHeader") public String RequestHeader( @RequestHeader(value = "Host",required = false) String encoding, @RequestHeader(value = "Connection",required = false) String Connection, @RequestHeader(value = "Accept-Encoding",required = false) String AcceptEncoding, @RequestHeader(value = "Accept-Language",required = false) String AcceptLanguage, @RequestHeader(value = "Cookie",required = false) String Cookie, @RequestHeader(value = "Accept",required = false) String Accept, Model uiModel ){ System.out.println(""); return "springmvc/RequestHeader"; } @RequestMapping(value = "CookieValue") public String CookieValue( @CookieValue(value = "JSESSIONID",required = false) String sessionId, HttpServletRequest request, HttpServletResponse response, Model uiModel ){ Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { System.out.println(cookie.getName() + ":" + cookie.getValue()); } Cookie cookie = new Cookie("token", "111111111111"); response.addCookie(cookie); return "springmvc/RequestHeader"; }