前端:
<th:block th:with="chrtype=${@config.getKey('sys.account.chrtype')}">
后端:
@Service("config")
public class ConfigValue {
@Autowired
ConfigService configService;
/**
* 根据键名查询参数配置信息
*/
public String getKey(String configKey){
return configService.selectConfigByKey(configKey);
}
}
说明:
${@config.getKey('sys.account.chrtype')} 实际上底层也是JAVA代码,代码类似于用JSP的<%%>从后端获取ConfigValue的对象实例,然后再调用getKey方法,thymeleaf归根结底只是一个前端的封装,最终底层编译都是JAVA。