编写controller
@Controller
@RequestMapping("/account")
public class AccountController {
//也可以不创建ModelAndView,直接在参数中指定
@RequestMapping(value = "/findAccount9")
public ModelAndView findAccount9(ModelAndView mv) {
mv.addObject("msg", "欢迎你 springmvc");
mv.setViewName("success");
return mv;
}
}
在index.jsp里面定义超链接
<a href="/account/findAccount9">ModelAndView参数传递</a>
编写controller
@Controller
@RequestMapping("/account")
public class AccountController {
@RequestMapping(value = "/findAccount10")
public String findAccount10(Model model) {
model.addAttribute("msg", "欢迎你 springmvc");
return "success";
}
}
在index.jsp里面定义超链接
<a href="/account/findAccount10">Model参数传递</a>
编写controller
@Controller
@RequestMapping("/account")
public class AccountController {
@RequestMapping("/findAccount11")
public String findAccount11(HttpServletRequest request,
HttpServletResponse response){
request.setAttribute("msg","欢迎你 springmvc");
return "success";
}
}
在index.jsp里面定义超链接
<a href="/account/findAccount11">ServletAPI传递</a>