beetl模板引擎使用筆記

maven項目pom:html

<dependency>
    <groupId>com.ibeetl</groupId>
    <artifactId>beetl</artifactId>
    <version>版本號</version>
</dependency>

spring-mvc.xml配置視圖解析web

<bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init"/>
     <!-- 定義beetl視圖文件解析-->
    <bean id="viewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
            <property name="contentType" value="text/html;charset=UTF-8"/>
            <property name="suffix" value=".html"/>
    </bean>

在resource 目錄下建立beetl.properties配置文件 自定義配置spring

#自定義配置
#模板根路徑
RESOURCE.root = /WEB-INF/views/
#定義模板全局變量的類
WEBAPP_EXT = com.zede.util.GlobalExt
#是否檢測文件變化
RESOURCE.autoCheck = true
#在頁面輸出錯誤提示信息
ERROR_HANDLER =org.beetl.ext.web.WebErrorHandler

GlobalExt.class:spring-mvc

public class GlobalExt implements WebRenderExt {

    /**
     * 這裏能夠配置模板 全局變量 如:template.binding("version","1.0");
     */
    @Override
    public void modify(Template template, GroupTemplate gtemplate, HttpServletRequest request,
            HttpServletResponse response) {

        template.binding("version", "1.0");
    }

}

能夠實現全部模板都能讀取 ${version} 這個變量mvc

 

==> 頁面顯示錯誤信息: ERROR_HANDLER =org.beetl.ext.web.WebErrorHandler
相關文章
相關標籤/搜索