前端页面如下:
<% if(@so.hasPermission("user:add")){ %>
<!--如果有权限再显示增加按钮-->
<button id="add-account" >添加帐号</button>
<% } %>
遇到的问题:
变量未定义(VAR_NOT_DEFINED):so,后面东改西改的,又遇到什么
该方法未注册(FUNCTION_NOT_FOUND):so.hasPermission之类的问题......后面终于在不懈的努力下,找到了解决办法!
解决方法如下
1、因为是和Springboot集成的,所以可以用下面的代码将beetl方法注册到groupTemplate里面:
import com.ibeetl.starter.BeetlTemplateCustomize;
import com.wf.ew.common.shiro.ShiroExt;
import org.beetl.core.GroupTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyBeetlConfig {
@Bean
public BeetlTemplateCustomize beetlTemplateCustomize() {
return new BeetlTemplateCustomize() {
public void customize(GroupTemplate groupTemplate) {
//将实现了shiro标签的beetl方法注册到groupTemplate里
groupTemplate.registerFunctionPackage("so", new ShiroExt());
}
};
}
}
2、因为我是刚刚接触这个beetl,所以还是小白,在前端页面上写法有问题,后面改成了:(去掉了@,不走java语法)
<% if(so.hasPermission("user:add")){ %>
<!--如果有权限再显示增加按钮-->
<button id="add-account" >添加帐号</button>
<% } %>
刷新页面,终于搞定,开森~~~