【问题标题】:How session attributes can be access by ThymeleafThymeleaf 如何访问会话属性
【发布时间】:2017-11-08 13:49:06
【问题描述】:

我尝试过以这种方式访问​​变量:

<p th:text="${#session.getAttribute('mySessionAttribute')}"></p>

@RequestMapping({"/"})
String index(HttpSession session) {
    session.setAttribute("mySessionAttribute", "someValue");
    return "index";
}

文档说:#session:直接访问与当前请求关联的 javax.servlet.http.HttpSession 对象。

我正在使用 Tomcat 8、Java 8、Spring Boot 和 Thymeleaf。

【问题讨论】:

标签: spring spring-boot thymeleaf


【解决方案1】:

documentation

您可以简单地使用&lt;p th:text="${session.mySessionAttribute}" /&gt;

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    相关资源
    最近更新 更多