首页 > 技术文章 > springmvc 中controller与jsp传值

dannyyao 2017-01-05 13:11 原文

参考: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";
    }

 

推荐阅读