2016-12-29 54 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')}