读书人

【web开发】基于引语spring的多方法请

发布时间: 2013-03-10 09:38:39 作者: rapoo

【web开发】基于注解spring的多方法请求的一种controller实现

仅作学习笔记,具体代码如下:

@Controller@RequestMapping(value="mainPage")  // 类对应的请求urlpublic class MainPageController extends AbstractController{                                                                                                                                                     // 实现Controller接口中的handleRequestInternal方法, 跳转时默认情况下会被调用    public ModelAndView handleRequestInternal(HttpServletRequest req,            HttpServletResponse res) throws Exception {        HashMap<String, Object> model = new HashMap<String, Object>();// TODO: add the model data                return new ModelAndView("mainPage",model);    // 'mainpage' is the view name       }    // 在请求url中带参数method=changePageNo时,该函数被调用    @RequestMapping(params = "method=changePageNo")    public ModelAndView changePageNo(@RequestParam("pageNo")String pageNo,      HttpSession session) throws Exception {   session.setAttribute("pageNo", pageNo);     HashMap<String, Object> model = new HashMap<String, Object>();// TODO: add the model data    return new ModelAndView("mainPage",model);     }           // ...可实现更多的对应不同参数url的控制方法}






读书人网 >Web前端

热点推荐