在Spring Boot中,我们可以使用ThymeleafViewResolver的addStaticVariable方法来添加全局变量,这些全局变量可以在所有的Thymeleaf模板中直接使用,而不需要在每个视图控制器中重复定义。 以下是一个简单的例子,展示如何在Spring Boot应用程序中添加全局变量: import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.thymeleaf.spring5.view.ThymeleafViewResolver; import org.thymeleaf.extras.javaexamples.dialect.JavaExamplesDialect; @Configuration public class ThymeleafConfig { @Bean public ThymeleafViewResolver...