SpringMVC框架之响应页面的五种方式
- 上一篇我为大家讲解到了使用SpringMVC框架接收页面数据的四种方式。本篇呢,我就为大家讲解一下SpringMVC框架如何响应页面。
- 第一种方式使用modelandview实现。代码如下
//第一种,使用modelandview实现
@RequestMapping(value = "/mavSelet")
public ModelAndView selectAll(){
modelAndView.addObject("list",123);
modelAndView.setViewName("index01.jsp");
return modelAndView;
}
- 第二种方式使用httpservletrrequest接口设置域的方式响应页面的方式
//方式二,使用httpservletrrequest接口设置域的方式响应页面的方式
@RequestMapping(value = "/requestS")
public String selectAll01(HttpServletRequest request){
request.setAttribute("list",123);
//返回到index01.jsp页面
return "index01.jsp";
}
- 第三种方式 使用model,将数据放在model中
//方式三,使用model,将数据放在model中
@RequestMapping(value = "/model")
public String selectAll02(Model model){
model.addAttribute("list",123);
return "index01.jsp";
}
//方式四,使用map,将数据放在map中
@RequestMapping("/hashmap")
public String selectAll03(HashMap<String, String> hashMap){
hashMap.put("list", "123");
return "index01.jsp";
}
//第五种使用modelmap方式
@RequestMapping(value = "/modelmap")
public String selectAll04(ModelMap modelMap){
modelMap.addAttribute("list",123);
return "index01.jsp" ;
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>${list}</h1>
</body>
</html>
- 使用EL表达式
- 以上就是SpringMVC响应页面的五种方式