Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何在thymeleaf中访问spring会话bean范围_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Spring mvc 如何在thymeleaf中访问spring会话bean范围

Spring mvc 如何在thymeleaf中访问spring会话bean范围,spring-mvc,spring-boot,thymeleaf,Spring Mvc,Spring Boot,Thymeleaf,我已经定义了我的对象 @组件 @范围(value=“session”,proxyMode=ScopedProxyMode.TARGET\u类) 公共班级会议{ 私有字符串消息; //吸气剂设定器 } 当我尝试从thymeleaf访问时,它失败了 解决方案 通过Springbeans访问 您可以访问直接会话属性 ${#session.getAttribute('mySessionAttribute')} 例如会话bean @Component @SessionScope public

我已经定义了我的对象

@组件
@范围(value=“session”,proxyMode=ScopedProxyMode.TARGET\u类)
公共班级会议{
私有字符串消息;
//吸气剂设定器
}
当我尝试从thymeleaf访问时,它失败了

解决方案

通过Springbeans访问

您可以访问直接会话属性

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

例如会话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>


什么是失败的?任何错误?错误消息:在null上找不到属性或字段“message”。但是,我找到了解决方案,通过SpringBeans访问
<span th:text="${pdfPropertyName}"></span>