Velocity模版自定义标签

	<!-- Velocity视图解析器 默认视图 -->
	<bean id="velocityViewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="contentType" value="text/html;charset=UTF-8" />
		<property name="viewNames" value="*.html" />
		<property name="suffix" value="" />
		<property name="dateToolAttribute" value="date" />
		<property name="numberToolAttribute" value="number" />
		<property name="toolboxConfigLocation" value="/WEB-INF/velocity-toolbox.xml" />
		<property name="requestContextAttribute" value="rc" />
		<property name="order" value="0" />
	</bean>

加上  <property name="toolboxConfigLocation" value="/WEB-INF/velocity-toolbox.xml" />   路径随便自己定义


现在创建velocity-toolbox.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<toolbox>
	<!-- velocity 自定义标签 -->
	<tool>
	    <key>shiro</key>
	    <scope>application</scope>
	    <class>com.wstro.shiro.VelocityShiro</class>
	</tool>
</toolbox>

key  随便自己定义  就是前台模版使用的

scope一般写application全局都能使用就可以了

class  使用到的类

前台直接调用


#if($shiro.hasPermission("backuprecord:save"))
			你有backuprecord:save  权限
			#end


类没有什么。和普通的java类一样;。方法不能是静态的,然后调用它的方法,可以传参


还有:freemarker自定义标签


原文地址:https://www.cnblogs.com/zhousiwei/p/10625858.html