Solon v3.0.3

solon-view-beetl [国产]

</> markdown
<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/templates/beetl.htm

<!DOCTYPE html>
<html>
<head>
    <title>${title}</title>
</head>
<body>
beetl::${msg};i18n::${@i18n.get("login.title")}
</body>
</html>

3、支持扩展定制示例

@Configuration
public class Config {
    @Bean
    public void configure(BeetlRender render){
        render.getProvider(); //:GroupTemplate
        render.getProviderOfDebug();
    }
}

4、自定义标签示例

以插件自带的权限验证标签为例:

<#authPermissions name="user:del">
我有user:del权限
</#authPermissions>

自定义标签和共享对象代码实现(自定义标签,v2.8.1 后支持注入):

@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";
    }
}