beetl拓展配置类,绑定一些工具类,方便在模板中直接调用
BeetlConfiguration.java
public class BeetlConfiguration extends BeetlGroupUtilConfiguration {
@Autowired
private Environment env;
@Autowired
private DictSelectorTag dictSelectorTag;
@Override
public void initOther() {
groupTemplate.registerFunctionPackage("shiro", new ShiroExt());
groupTemplate.registerFunctionPackage("tool", new ToolUtil());
groupTemplate.registerFunctionPackage("kaptcha", new KaptchaUtil());
groupTemplate.registerTagFactory("dictSelector", () -> dictSelectorTag);
groupTemplate.registerFunction("env", new Function() {
@Override
public String call(Object[] paras, Context ctx) {
String key = (String) paras[0];
String value = env.getProperty(key);
if (value != null) {
return getStr(value);
}
if (paras.length == 2) {
return (String) paras[1];
}
return null;
}
String getStr(String str) {
try {
return new String(str.getBytes("iso8859-1"), StandardCharsets.UTF_8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
});
}
}
BeetlConfiguration扩展配置
点赞
收藏