@RequestMapping參數value和params的區別


value的值可以是一個url地址的形式或者正則表達式或者rest風格的形式,而params正如其名是參數,訪問的時候params的值只能作為參數,不能作為訪問的地址,請看下例>

value的使用

    @RequestMapping(value="list",method=RequestMethod.GET)
    public String getEmployeeData(ModelAndView mav,HttpServletRequest request,HttpServletResponse response){
        System.out.println("============");
        return "test";
    }

訪問的地址可以是/xx項目名/xxcontroller名/list

params的使用

@RequestMapping(value="list",params="one",method=RequestMethod.GET)
    public String getEmployeeData(ModelAndView mav,HttpServletRequest request,HttpServletResponse response){
        System.out.println("============");
        return "test";
    }

這種方式如果兩個方法的value值相同,只需要加上參數one即可區別,訪問的地址為/xx項目名/xxcontroller名/list?one

或者

@RequestMapping(params="list",method=RequestMethod.GET)
    public String getEmployeeData(ModelAndView mav,HttpServletRequest request,HttpServletResponse response){
        System.out.println("============");
        return "test";
    }

這種方式要訪問該方法的地址為:/xx項目名/xxcontroller名?list,沒錯,這里沒有方法名,list只是參數。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM