SpringMVC中的数据传递

将数据由控制层传到视图层

  • 使用Model对象,实际上是一个Map,同样可以使用Map代替

  • 当视图是jsp时,model被放在了request中,也就是说可以在jsp中使用el表达式取出

    @Controller public class ListController { @RequestMapping("/list") public String getList(Model model){ ArrayList students = new ArrayList<>(); students.add("佩奇"); students.add("喜羊羊"); students.add("大雄"); model.addAttribute("students", students); return "studentList"; } //使用Map代替Model @RequestMapping("/listMap") public String getStudents(Map model){ ArrayList students = new ArrayList<>(); students.add("佩奇"); students.add("喜羊羊"); students.add("大雄"); model.put("students", students); return "studentList"; } }

接受请求中的数据

在这里:https://my.oschina.net/u/3291293/blog/1818905

评论

暂无评论