Spring MVC之——数据传递
1.ModelAndView传递
-
编写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>
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参数传递</a>
ServletAPI传递
-
编写controller文章来源:https://www.toymoban.com/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里面定义超链接文章来源地址https://www.toymoban.com/news/detail-801979.html
<a href="/account/findAccount11">ServletAPI传递</a>
到了这里,关于Spring MVC学习之——数据传递(在页面上添加数据)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!