控制器:
package com.awaimai.web;
import com.alibaba.fastjson.JSONObject;
import org.hibernate.validator.constraints.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@Controller
@Validated
public class kzq
{
@RequestMapping(value = "/test3")
public String test3(HttpSession session)
{
session.setAttribute("aa","1234");
session.setAttribute("bb","abcd");
session.setAttribute("cc","defg");
return "index";
}
}
html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"</html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p th:text="${session.aa}">ceshi</p>
<p th:text="${session.bb}">ceshi</p>
<p th:text="${session.cc}">ceshi</p>
</body>
</html>
web访问: