thymeleaf全局变量定义
thymeleaf全局变量定义
1、 重写configureViewResolvers⽅法thyme
/**
* @author : fzz
*/
@Component
public class WebMvcConfigurerAdapter implements WebMvcConfigurer {
@Resource(name="thymeleafViewResolver")
private ThymeleafViewResolver thymeleafViewResolver;
@Value("${v}")
private String version ="DEV";
@Override
public void configureViewResolvers(ViewResolverRegistry registry){
if(thymeleafViewResolver != null){
Map<String, Object> vars =new HashMap<>(1);
vars.put("version", version);
thymeleafViewResolver.setStaticVariables(vars);
}
figureViewResolvers(registry);
}
}
2、html中应⽤
<div class="environmentclass"data-value="${version}">

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。