Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 boot 如果存在SpringBean,我如何签入Thymeleaf_Spring Boot_Thymeleaf - Fatal编程技术网

Spring boot 如果存在SpringBean,我如何签入Thymeleaf

Spring boot 如果存在SpringBean,我如何签入Thymeleaf,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我正在编写一个Thymeleaf模板,它将从Springbean获取一些数据。我的项目正在使用SpringBoot(如果有必要的话)。有些情况下,某个bean不可用。如何在模板内部检查bean是否存在 我试着检查一个变量,但不起作用 <div th:if="${@myBean != null}" th:text="Bean exists"></div> 我得到一份工作 NoSuchBean定义异常:没有名为“myBean”的bean可用 使用 更简单的是,您可以检

我正在编写一个Thymeleaf模板,它将从Springbean获取一些数据。我的项目正在使用SpringBoot(如果有必要的话)。有些情况下,某个bean不可用。如何在模板内部检查bean是否存在

我试着检查一个变量,但不起作用

<div th:if="${@myBean != null}" th:text="Bean exists"></div>

我得到一份工作

NoSuchBean定义异常:没有名为“myBean”的bean可用

使用


更简单的是,您可以检查Spring控制器中是否存在bean。

您可以为您的模型设置一个指示器我已经搜索过了,我似乎找不到一种方法来实现这一点……正如我担心的那样,同样的异常被抛出,因为可能
nullSafe()
方法只做了一个空比较,就像我做的那样(请参见问题)。对于文档porpouses,我想到的是
${#objects.nullSafe(@myBean,@existingBean.someMethod()}
${#objects.nullSafe(obj,default)}