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

SSH 框架controller向jsp傳遞List jsp中使用el表達式獲取

color 表單 src 模擬 如何 bsp alt 分享 pri

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

技術分享圖片

SSH 框架controller向jsp傳遞List jsp中使用el表達式獲取