1. 程式人生 > >SSH 框架controller向jsp傳遞List jsp中使用el表示式獲取

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專案即可