springmvc数据处理模型

1、ModelAndView

 实现:

@RequestMapping("/testModelAndView")
    public ModelAndView testModelAndView() {
        modelAndView.addObject("name", "hy");
        return modelAndView;
    }

页面获取:

<%
System.out.println(request.getAttribute("name"));
%>
name: ${requestScope.name }

 

2、Map

 使用map作为参数,向map中放值,参数也可以是model、modelmap

@RequestMapping("/testMap")
    public String testMap(Map<String,Object> map) {
        map.put("user", new User("ht", "123456", "ht@sina.com"));
        return SUCCESS;
    }

页面获取:

user: ${requestScope.user }

 

3、SessionSttributes

使用这个注解可以将值放在session域中

@SessionAttributes(names={"user"},types={User.class})

当向请求域中放user的时候也会同时向session里面放一份

页面:

    session user: ${sessionScope.user }

 

posted on 2016-12-18 22:06  _故乡的原风景  阅读(212)  评论(0编辑  收藏  举报