博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
thymeleaf 自定义标签
阅读量:4325 次
发布时间:2019-06-06

本文共 1743 字,大约阅读时间需要 5 分钟。

/**  * @author candy  * @since 16/1/13.  */ @Component public class CmsDialect extends AbstractDialect {
@Override public String getPrefix() {
return "crm"; } @Override public Set
getProcessors() {
final Set
processors = new HashSet<>(); processors.add(new FragmentElementProcessor()); return processors; } }
@Component public class FragmentElementProcessor extends AbstractMarkupSubstitutionElementProcessor {
public FragmentElementProcessor() {
super("fragment"); } @Override protected List
getMarkupSubstitutes(Arguments arguments, Element element) {
final ApplicationContext appCtx = ((SpringWebContext)arguments.getContext()).getApplicationContext(); final String path = element.getAttributeValue("path"); final FragmentManager fragmentManager =appCtx.getBean(FragmentManager.class); final String content = fragmentManager.findReleasedContent(path); final Element container = new Element("div"); final Text text = new Text(content); container.addChild(text); /* * The abstract IAttrProcessor implementation we are using defines * that a list of nodes will be returned, and that these nodes * will substitute the tag we are processing. */ final List
nodes = new ArrayList<>(); nodes.add(container); return nodes; } @Override public int getPrecedence() {
return 1000; } } 自定义标签的使用
  
官网的链接地址:http://www.thymeleaf.org/doc/tutorials/2.1/extendingthymeleaf.html#attribute-processors

转载于:https://www.cnblogs.com/yiyaopeng/p/5130181.html

你可能感兴趣的文章
SynchronousQueue
查看>>
Python学习笔记-EXCEL操作
查看>>
依照特定轨迹遍历字符串图
查看>>
Mantis 1.1.0 报告问题中设置必填项或取消必填项[Z]
查看>>
爬虫添加代理
查看>>
POJ 题目1204 Word Puzzles(AC自己主动机,多个方向查询)
查看>>
oracle经常使用函数(2)
查看>>
Iocomp控件之数字显示【图文】
查看>>
Androd开发之广告栏设计
查看>>
jquery.fly.min.js 拋物插件
查看>>
mini2440系统引导(五)串口UART
查看>>
JDK5.0新特性系列---9.注释功能Annotation
查看>>
普通平衡树(指针splay)
查看>>
【HEOI 2018】Day2 T2 林克卡特树
查看>>
vue-cli中配置sass的方法
查看>>
使用CSS3 @font-face【实现个性化字体 】
查看>>
codereview tool
查看>>
input type=file 标签禁止让用户手动输入
查看>>
一个诡异的WCF问题
查看>>
自定义adapter 的getView方法被重复执行了n次的解决方法
查看>>