天天看點

spingMVC session注解中放多個key值

spingMVC session注解中放多個key值

關于springMVC @sessionAttribue注解

@SessionAttributes({“uname”,“age”})//用{“key”,“key”}存放多個key值

Controller代碼:

@Controller
@RequestMapping("user")
@SessionAttributes({"uname","age"})//用{"key","key"}存放多個key值
public class AnnotationController {
	@RequestMapping(value="/login.do",method=RequestMethod.POST)
	public String forTest1(String uname,Integer age,Model md){
		md.addAttribute("uname",uname);
		md.addAttribute("age",age);
		return "test";
	}
}

           

輸入的jsp頁面

login.jsp:

<html>
  <head>
  </head>
  <body>
	<form action="${pageContext.request.contextPath}/user/login.do" method="post">
		姓名:<input type="text" name="uname"/>
		年齡:<input type="text" name="age">
		<input type="submit" value="送出">
	</form>
  </body>
</html>
           

取值的jsp頁面

test.jsp:

<html>
  <head>
    <title>My JSP 'test.jsp' starting page</title>
  </head>
  <body>
    ${uname}
    ${age}
  </body>
</html>
           

下面是請求過去時得到的model裡的值:

spingMVC session注解中放多個key值

下面是直接通路test.jsp頁面:

spingMVC session注解中放多個key值

這裡就從session裡取到參數了

總結:

@SessionAttributes({“uname”,“age”})

用{“key”,“key”}存放多個key值

繼續閱讀