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

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;

如图

 

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

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

验证一下,已经传入了

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

猜你喜欢

转载自www.cnblogs.com/jnhs/p/10005931.html