solon.view.beetl [国产]
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.view.beetl</artifactId>
</dependency>
1、描述
视图扩展插件,为 Solon View 提供基于 beetl(代码仓库)的框架适配。
2、应用示例
DemoController.java
//顺便,加个国际化在模板里的演法
@I18n
@Controller
public class DemoController{
@Mapping("/test")
public ModelAndView test() {
ModelAndView model = new ModelAndView("beetl.htm");
model.put("title", "dock");
model.put("msg", "你好 world!");
return model;
}
}
resources/WEB-INF/templates/beetl.htm
<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
</head>
<body>
beetl::${msg};i18n::${@i18n.get("login.title")}
</body>
</html>
3、支持事件扩展定制示例
public class App {
public static void main(String[] args) {
Solon.start(App.class, args, app->{
app.onEvent(GroupTemplate.class, e -> {
//可能会获取两次事件(一个是 debug 模式下才有的)
});
});
}
}
4、自定义标签示例
以插件自带的权限验证标签为例:
<#authPermissions name="user:del">
我有user:del权限
</#authPermissions>
自定义标签和共享对象代码实现:
@Component("view:authPermissions")
public class AuthPermissionsTag extends Tag {
@Override
public void render() {
String nameStr = (String) getHtmlAttribute(AuthConstants.ATTR_name);
String logicalStr = (String) getHtmlAttribute(AuthConstants.ATTR_logical);
if (Utils.isEmpty(nameStr)) {
return;
}
String[] names = nameStr.split(",");
if (names.length == 0) {
return;
}
if (AuthUtil.verifyPermissions(names, Logical.of(logicalStr))) {
this.doBodyRender();
}
}
}
@Component("share:demo1")
public class Demo {
public String hello(){
return "hello";
}
}