码迷,mamicode.com
首页 > 其他好文 > 详细

gboot 配置 beetl模板引擎

时间:2019-07-28 09:39:17      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:artifact   配置   path   view   res   lsp   模板引擎   you   ini   

1、配置 maven 依赖

<!-- beetl模板引擎 -->
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.8.5</version>
</dependency>
2、配置 BeetlConfig

package com.sample.common.config;

import org.beetl.core.resource.WebAppResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;

import java.io.IOException;

@Configuration
public class BeetlConfig {

@Bean(initMethod = "init")
public BeetlGroupUtilConfiguration beetlGroupUtilConfiguration() {
BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader());
try {
// WebAppResourceLoader 配置root路径是关键
WebAppResourceLoader webAppResourceLoader =
new WebAppResourceLoader(patternResolver.getResource("classpath:/").getFile().getPath());//设置beetl根路径
beetlGroupUtilConfiguration.setResourceLoader(webAppResourceLoader);
} catch (IOException e) {
e.printStackTrace();
}
beetlGroupUtilConfiguration.setConfigFileResource(patternResolver.getResource("classpath:beetl.properties"));
//读取配置文件信息
return beetlGroupUtilConfiguration;
}

@Bean(name = "beetlViewResolver")
public BeetlSpringViewResolver getBeetlSpringViewResolver() {
BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
beetlSpringViewResolver.setPrefix("beetls/");//设置beetl文件的路径为:resources/templates
beetlSpringViewResolver.setSuffix(".html");//设置beetl的后缀设置为btl
beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
beetlSpringViewResolver.setOrder(0);
beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration());
return beetlSpringViewResolver;
}


}
3、创建 beetl 文件目录

 

4、文件内容

head.html

<meta charset="UTF-8">
<title>header</title>
foot.html

<div>footer</div>
default.html

<!DOCTYPE html>
<html>
<head>
<% include(‘../include/header.html‘){} %>
</head>
<body>
<div class="wrapper">${layoutContent}</div>
<% include(‘../include/footer.html‘){} %>
</body>
</html>

beetl.html

<% layout("layouts/default.html"){ %>
Hello world!
<% } %>
5、配置文件 beetl.properties

#取值开始符号
DELIMITER_PLACEHOLDER_START=${
#取值结束符号
DELIMITER_PLACEHOLDER_END=}
#beetl代码开始符号
DELIMITER_STATEMENT_START=<%
#beetl代码结束符号
DELIMITER_STATEMENT_END=%>
 
---------------------

gboot 配置 beetl模板引擎

标签:artifact   配置   path   view   res   lsp   模板引擎   you   ini   

原文地址:https://www.cnblogs.com/liyanyan665/p/11257596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!