模型数据处理 —— @SessionAttributes

@SessionAttributes

Demo1(未加@SessionAttributes)

SpringMVCTest.java

package org.fool.springmvc;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class SpringMVCTest {
	@RequestMapping("/testSessionAttributes")
	public String testSessionAttributes(Model model) {
		User user = new User("Hello", "World", new Date());
		
		model.asMap().put("user", user);
		
		return "success";
	}
}

 success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>success page</title>
</head>
<body>
	request user: ${requestScope.user }
	
	<br><br>
	
	session user: ${sessionScope.user }
	
	<br><br>
</body>
</html>

 Result

 Demo2(添加@SessionAttributes)


 Result


 

Demo3(使用types属性值)


 Result


 
 

猜你喜欢

转载自agilestyle.iteye.com/blog/2317836