话不多说直接上代码
后端代码:
//创建session对象 HttpSession session = request.getSession(true); session.setAttribute("USER_INFO",userInfo);//把用户数据保存到session对象中
前端代码:
<span class="x-red" th:text="${session.USER_INFO.uName}"/>
后端代码:
servletContext.setAttribute("COUNT",val);
前端代码:
<cite th:text="${#servletContext.getAttribute(‘COUNT‘)}">99</cite>
thymeleaf从session中获取用户信息,thymeleaf从servletContext获取信息
原文:https://www.cnblogs.com/book-mountain/p/11817117.html