2016-12-29 108 views
2

我定義我的對象如何進入春季會話bean範圍,thymeleaf

@Component 
    @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) 
    public class MySession { 
     private String message; 

    // getter setter 
    } 

當我嘗試從thymeleaf未能訪問。

<p th:text="${mySession.message}"></p> 

SOLUTION

通過訪問Spring bean的

http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html

<p th:text="${@mySession.getMessage()}"></p> 
+0

什麼是失敗?有什麼錯誤? – Patrick

+0

錯誤消息:無法在null上找到屬性或字段「消息」。但是,我發現瞭解決方案,通過春豆訪問 – prptn

回答

0
session.setAttribute("mySessionAttribute", "someValue"); 

您可以直接訪問會話屬性。

${#session.getAttribute('mySessionAttribute')}