关于springmvc4.0的sessionAttributes注解的问题
         我看佟刚老师的springmvc4.0的视频,在类上加一个@SessionAttributes({"user"})
    注解,就可以把map里面的值也放到session域里面去,可是我为什么还是获取不到值啊!但是我如果加类型的话, 就可以获取类型的值.代码如下:
    TestController:

@SessionAttributes(value="{user}",types={String.class})
@RequestMapping(value="/test")
@Controller
public class TestController {
private static final String SUCCESS = "success";

 @RequestMapping("/testSessionAttribute")
public String testSessionAttribute(Map<String,Object> map){
    User user = new User("Tom","123456","tom@atguigu.com",15);
    map.put("user", user);
    map.put("school", "atguigu");
    return SUCCESS;
}

}

success.jsp:
request user: ${requestScope.user }

session user: ${sessionScope.user } <br/><br/>

request school: ${requestScope.school } <br/><br/>

session school: ${sessionScope.school } <br/><br/>

页面效果:
![图片说明](https://img-ask.csdn.net/upload/201610/16/1476590680_213363.png)

1个回答

@SessionAttributes(value="{user}",types={String.class}),你把"{user}"的{}去掉试试?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问