【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的控制方法}