仅作学习笔记,具体代码如下:
@Controller
@RequestMapping(value="mainPage") // 类对应的请求url
public 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的控制方法
}
本文介绍了一个使用Spring MVC框架的简单控制器示例,包括基本的页面跳转和带有参数的方法处理。通过设置请求映射和参数处理展示了如何灵活地响应不同的URL请求。

被折叠的 条评论
为什么被折叠?



