本博客介绍的是基于springboot 2.0 thymeleaf3.0 版本的自定义标签
AbstractMarkupSubstitutionElementProcessor 这个类是thymeleaf 3.0以前的版本中使用的,thymeleaf 3.0以后用AbstractProcessorDialect类代替。
1、在pom中加入thymeleaf3.0
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、新建自定义标签注册类
package com.bmSystem.sys.config.customLabel;
import java.util.HashSet;
import java.util.Set;
import org.springframework.stereotype.Component;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;
// ~ File Information
/**
* @author zxy
* @date 2019年7月22日 下午2:31:56
* 类说明:自定标签注册类
*/
// ====================================================================================================================
@Component
public class CustomLabel extends AbstractProcessorDialect{
/**
* 定义方言名称
*/
private static final String NAME="系统自定义标签";
/**
* 定义方言属性
*/
private static final String PREFIX="bm";
protected CustomLabel() {
super(NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
}
@Override
public Set<IProcessor> getProcessors(final String dialectPrefix) {
final Set<IProcessor> processor=new HashSet<>();
processor.add(new CustomLabelSelect(PREFIX));//<bm:select>标