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项目即可

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM