`

模型数据处理 —— @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


 
 

 

 

 

  • 大小: 487.9 KB
  • 大小: 18 KB
  • 大小: 29.1 KB
  • 大小: 21.2 KB
  • 大小: 38.1 KB
  • 大小: 32 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics