SpringBoot整合freemarker中自定义标签获取字典表的数据
@Component
public class DictDirective implements TemplateDirectiveModel { @Override
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
if(map.containsKey("type") && map.get("type") != null){
String type = map.get("type").toString();
List<Dict> dictList = DictUtils.getDictList(type);
if(map.containsKey("value") && map.get("value") != null){
String value = map.get("value").toString();
Dict dict = null;
for (Dict dict1 : dictList) {
if(value.equals(dict1.getValue().toString())){
dict = dict1;
}
}
environment.setVariable("dict", builder.build().wrap(dict));
}else{
environment.setVariable("dictList", builder.build().wrap(dictList));
}
}
if(templateDirectiveBody!=null){
templateDirectiveBody.render(environment.getOut());
}
}
}
@Component
public class FreemarkerConfig {
@Autowired
private Configuration configuration;
@Autowired
private DictDirective dictDirective; @PostConstruct
public void setSharedVariable() throws TemplateModelException {
configuration.setSharedVariable("dict_tag", dictDirective);
}
}
<@dict_tag type="news_source" value="${news.source}">
${dict.label}
</@dict_tag>

SpringBoot整合freemarker中自定义标签获取字典表的数据的更多相关文章
- SpringBoot 整合mongoDB并自定义连接池
SpringBoot 整合mongoDB并自定义连接池 得力于SpringBoot的特性,整合mongoDB是很容易的,我们整合mongoDB的目的就是想用它给我们提供的mongoTemplate,它 ...
- SpringBoot整合freemarker 引用基础
原 ElasticSearch学习笔记Ⅲ - SpringBoot整合ES 新建一个SpringBoot项目.添加es的maven坐标如下: <dependency> <groupI ...
- springboot整合freemarker
前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...
- springboot 整合 freemarker
springboot 整合 freemarker 依赖 <parent> <groupId>org.springframework.boot</groupId> & ...
- 【SpringBoot】09.SpringBoot整合Freemarker
SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.apache.org ...
- springboot整合freemarker模板引擎后在页面获取basePath绝对路径
在项目中引用静态资源文件或者进行ajax请求时我们有时候会使用 ${basePath} ,其实这就是一种获取绝对路径的方式: 那么在springboot项目中要怎么配置才能使用 basePaht呢? ...
- springMVC+freemarker实现自定义标签
在开发过程中,有些需要引用到重复的页面,或者动态的数据 修改数据库是可以实现,但是太麻烦了. freemarker自定义标签在开发中用途很广,就说个入门实例吧 基于springmvc. 首先需要导入对 ...
- jsp页面中自定义标签的小演示
在实习期遇到公司的pg自定义标签了,同事要我自己自学一下 自定义标签是用户定义的JSP语言元素.当JSP页面包含一个自定义标签时将被转化为servlet.JSP标签扩展可以让你创建新的标签并且可以直接 ...
- 基于SpringBoot 、AOP与自定义注解转义字典值
一直以来,前端展示字典一般以中文展示为主,若在表中存字典值中文,当字典表更改字典值对应的中文,会造成数据不一致,为此设置冗余字段并非最优方案,若由前端自己写死转义,不够灵活,若在业务代码转义,臃肿也不 ...
随机推荐
- shell脚本,如何监控mysql数据库。
[root@localhost wyb]# cat jkmysql #!/bin/bash status=`/etc/init.d/mysqld status|grep running|wc -l` ...
- 【Git版本控制】Git使用教程
1.Git的综述 SVN是集中式版本控制系统,版本库集中放在中央服务器上,而干活时用的都是自己的电脑,所以首先要从中央服务器哪里得到最新的版本,然后干活,干完后,需要把自己做完的活推送到中央服务器.集 ...
- (53)zabbix模板
zabbix模板是做什么的? 平时工作中,我们需要监控web.mysql.redis.nginx这些服务器,众多服务器的业务都是一样的,所以我们只要事先创建好模板,然后所有服务器链接这个模板即可,如果 ...
- (50)zabbix API二次开发使用与介绍
zabbix API开发库 zabbix API请求和响应都是json,并且还提供了各种语法的lib库,http://zabbix.org/wiki/Docs/api/libraries,包含php. ...
- (8)zabbix监控项item是什么
什么是item Items是从主机里面获取的所有数据.通常情况下我叫itme为监控项,例如服务器加入了zabbix监控,我需要监控它的cpu负载,那么实现这个方法的东西就叫item item构成 it ...
- grafana绘制图表
安装方法 系统为ubuntu16 1首先添加以下到/etc/apt/sources.list: deb https://packagecloud.io/grafana/stable/debian/ s ...
- TSOJ--2018 江苏省省赛
[2018 江苏省大学生程序设计大赛] K. 2018 (测试数据范围有扩大) Problem Given a, b, c, d, find out the number of pairs of int ...
- pymongo使用方法
MongoDB存储 在这里我们来看一下Python3下MongoDB的存储操作,在本节开始之前请确保你已经安装好了MongoDB并启动了其服务,另外安装好了Python 的PyMong ...
- iOS 绕过https证书验证 请求数据
HTTPS和HTTP: 1.https协议需要到ca申请证书,一般免费证书很少,需要交费. 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议. 3.http ...
- 2017 Multi-University Training Contest - Team 2
Regular polygon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...