springmvc 中controller與jsp傳值


參考:springmvc 中controller與jsp傳值

        springMVC:將controller中數據傳遞到jsp頁面

jsp中,死活拿不到controller中的變量。

花了半天,網上列出各種原因。最后發現,是自己對springmvc中controller和jsp的傳值不理解導致

controller的方法中需要返回Model的,這點是springmvc和struct的不同

第二種方法無法返回,后續再探究為啥

//列表
    @RequestMapping("/listAll")
    public String listAll(Map<String,Object> model){
        List<Person> personList = ps.listAll();
        model.put("personList", personList);
        
        System.out.println(" listall hello");
        
        return "person/jPersonList";
    }
    
    //列表
    @RequestMapping("/listAllOther")
    public String listAllOther(Model model){
        List<Person> personList1 = ps.listAll();
        model.addAttribute(personList1);
        
        System.out.println(" listallother1 hello");
        
        return "person/jPersonList";
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM