参考此文http://blog.sina.com.cn/s/blog_6d3c1ec601014h1h.html

1 使用ModelAndVoew

引入:org.springframework.web.servlet.ModelAndView

ModelAndView如其名称所示,它代表了Spring Web MVC中呈现画面时所使用的Model与View,由于Java一次只能返回一个物件,所以ModelAndView的作用封装这两个物件,以方便一次返回Model与View这两个物件。

controller的代码

@RequestMapping("/list")
    public ModelAndView getStudentList() {
        ModelAndView mav = new ModelAndView();
        mav.addObject("studentListSimulate", studentListSimulate);
        mav.setViewName("jsp/student_list");
        return mav;
    }

 

在页面student_list中使用el表达式取值就可以,需要在jsp头部引入jstl

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

jnhs-SpringMVC的controller向jsp传递数据的五种方式

效果如下

jnhs-SpringMVC的controller向jsp传递数据的五种方式

 未完待续

 

相关文章:

  • 2022-01-21
  • 2021-10-03
  • 2022-01-27
  • 2022-12-23
  • 2021-11-01
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-28
  • 2021-05-26
相关资源
相似解决方案