Spring MVC之——數(shù)據(jù)傳遞
1.ModelAndView傳遞
-
編寫controller
@Controller @RequestMapping("/account") public class AccountController { //也可以不創(chuàng)建ModelAndView,直接在參數(shù)中指定 @RequestMapping(value = "/findAccount9") public ModelAndView findAccount9(ModelAndView mv) { mv.addObject("msg", "歡迎你 springmvc"); mv.setViewName("success"); return mv; } }
-
在index.jsp里面定義超鏈接
<a href="/account/findAccount9">ModelAndView參數(shù)傳遞</a>
Model傳遞
-
編寫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參數(shù)傳遞</a>
ServletAPI傳遞
-
編寫controller文章來源:http://www.zghlxwxcb.cn/news/detail-801979.html
@Controller @RequestMapping("/account") public class AccountController { @RequestMapping("/findAccount11") public String findAccount11(HttpServletRequest request, HttpServletResponse response){ request.setAttribute("msg","歡迎你 springmvc"); return "success"; } }
-
在index.jsp里面定義超鏈接文章來源地址http://www.zghlxwxcb.cn/news/detail-801979.html
<a href="/account/findAccount11">ServletAPI傳遞</a>
到了這里,關(guān)于Spring MVC學(xué)習(xí)之——數(shù)據(jù)傳遞(在頁面上添加數(shù)據(jù))的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!