springmvc 中controller与jsp传值

参考:springmvc 中controller与jsp传值spring

        springMVC:将controller中数据传递到jsp页面mvc

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

花了半天,网上列出各类缘由。最后发现,是本身对springmvc中controller和jsp的传值不理解致使jsp

controller的方法中须要返回Model的,这点是springmvc和struct的不一样spa

第二种方法没法返回,后续再探究为啥.net

//列表
    @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";
    }
相关文章
相关标签/搜索