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与自定义注解转义字典值
一直以来,前端展示字典一般以中文展示为主,若在表中存字典值中文,当字典表更改字典值对应的中文,会造成数据不一致,为此设置冗余字段并非最优方案,若由前端自己写死转义,不够灵活,若在业务代码转义,臃肿也不 ...
随机推荐
- word转HTML在layuiadmin中锚点调转问题
前言: 在以前我们讲过把word转成HTML移植入自己的web项目使用:Word转html并移植到web项目 正文: 发现如果在layuiadmin框架中,页面里锚点跳转时会不正常(会跳转到新页面): ...
- 628. Maximum Product of Three Numbers@python
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- 简单jQuery图片自适应宽度插件jQuery.imgAutoSize.js
(function ($) { var loadImg = function (url, fn) { var img = new Image(); img. ...
- UVa 167(八皇后)、POJ2258 The Settlers of Catan——记两个简单回溯搜索
UVa 167 题意:八行八列的棋盘每行每列都要有一个皇后,每个对角线上最多放一个皇后,让你放八个,使摆放位置上的数字加起来最大. 参考:https://blog.csdn.net/xiaoxiede ...
- MySQL Group Replication(组复制MGR)
MGR基本要求: 1.InnoDB存储引擎 2.主键,每个表必须具有已定义的主键或等效的主键,其中等效项是非null唯一键 3.IPv4网络 4.网络性能 5.开启二进制日志并开启GTID模式 6.m ...
- vue-music:歌词的其他功能
由于歌词的播放需要歌曲播放,切换歌曲,歌曲的播放模式等等有关联,因此,需要在这几处处理相关问题 1.循环播放回不到开始位置 loop() { this.$refs.audio.currentTime ...
- CVS update常用技巧
常用的命令有 cvs update 全部更新 cvs update path/to/file 来更新某一个文件 cvs update -dP 意为删除空目录创建新目录 cvs -f -n update ...
- 1 producer — n consumers 模型 实现
#include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> ...
- 关于Linux下使用expdp和impdp命令对Oracle数据库进行导入和导出操作
说明:本次导入和导出采用expdp和impdp命令进行操作,这2个命令均需要在服务器端进行操作 http://www.cnblogs.com/huacw/p/3888807.html 一. 从O ...
- Fiddler-给手机设置代理并抓取https链接
注:有两部分fiddler设置和手机端设置,且配置完成后,使用时确保PC和手机连接同一WiFi 设置方法如下: 1.上网搜索fiddler官方版下载,并安装完成后,开启fiddler 2.选择Tool ...