mvc可以使用ModelAndViev传递数据选择跳转的视图

controller中的代码, 把一个模拟的表单studentListSimulate传给ModelAndView

    @RequestMapping("/detial")
    public Model showStudentDetial(Model mod) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("studentListSimulate", studentListSimulate);
        mav.setViewName("jsp/student_detial");
        return mod;
    }

jsp中可以使用el表达式获取model中studentListSimulate的元素,然后再通过实体类的属性,获取属性的值

这是model实体类中的属性

public class StudentModel {
    private int studentIdInModel;
    private String studentNameInModel;
    private int studentAgeInModel;

如图

 SSH 框架controller向jsp传递List jsp中使用el表达式获取

如果,是从数据库里查询到一个list怎么办呢? 如何从controller中向jsp传递呢?

同样是 把list传给ModelAndView ,只不过这次的list变了,是在dao中生成,返回给service然后再返回给controller的

SSH 框架controller向jsp传递List jsp中使用el表达式获取

验证一下,已经传入了

SSH 框架controller向jsp传递List jsp中使用el表达式获取

前台,使用el表达式获取model中的list项目即可

SSH 框架controller向jsp传递List jsp中使用el表达式获取

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2022-01-28
  • 2021-11-29
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
相关资源
相似解决方案