我已经定义了我的对象
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class MySession {
private String message;
// getter setter
}
当我尝试从胸腺访问时,它失败了。
<p th:text="${mySession.message}"></p>
解决方案
通过弹簧豆访问
http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html
<p th:text="${@mySession.getMessage()}"></p>
session.setAttribute("mySessionAttribute", "someValue");
您可以访问直接会话属性。
${#session.getAttribute('mySessionAttribute')}
例如session bean
@Component
@SessionScope
public class State implements Serializable {
private String pdfPropertyName;
public String getPdfPropertyName() {
return pdfPropertyName;
}
public void setPdfPropertyName(String pdfPropertyName) {
this.pdfPropertyName = pdfPropertyName;
}
}
在控制器中
@Controller
@RequestMapping("uploadPdf")
public class UploadPdfController {
@Autowired State state;
@ModelAttribute("pdfPropertyName")
public String getPdfPropertyName() {
return state.getPdfPropertyName();
}
}
可以通过
访问<span th:text="${pdfPropertyName}"></span>