一、前言
階段性的寫一些東西記錄,之前在做項目時就使用過beetl,今天決定寫篇文章記錄下來,這篇是eclipse。
二、瞭解beetl
三、開始整合
3.1 首先需要搭建一個SSM的基礎框架,如果不會,網上有一些教程。
3.2引入beetl所需要的jar包
如果是maven項目,在pom文件中加入beetl的jar包,版本號可根據需要修改。
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>2.7.27</version>
</dependency>
3.3添加beetl.properties配置文件
這個配置文件是我從官網上複製下來的,有一些覺得用不到的就給註釋了。
不知道這些都是什麼含義的,在官方文檔上都是可以找到的。
#默認配置
ENGINE=org.beetl.core.engine.FastRuntimeEngine
DELIMITER_PLACEHOLDER_START=${
DELIMITER_PLACEHOLDER_END=}
DELIMITER_STATEMENT_START=<%
DELIMITER_STATEMENT_END=%>
#DIRECT_BYTE_OUTPUT = FALSE
#HTML_TAG_SUPPORT = true
#HTML_TAG_FLAG = #
#HTML_TAG_BINDING_ATTRIBUTE = var
#NATIVE_CALL = TRUE
TEMPLATE_CHARSET = UTF-8
#ERROR_HANDLER = org.beetl.core.ConsoleErrorHandler
#NATIVE_SECUARTY_MANAGER= org.beetl.core.DefaultNativeSecurityManager
#MVC_STRICT = FALSE
#資源配置,resource後的屬性只限於特定ResourceLoader
#RESOURCE_LOADER=org.beetl.core.resource.ClasspathResourceLoader
#classpath 根路徑
RESOURCE.root= /
#是否檢測文件變化,開發用true合適,但線上要改爲false
#RESOURCE.autoCheck= true
#自定義腳本方法文件的Root目錄和後綴
#RESOURCE.functionRoot = functions
#RESOURCE.functionSuffix = html
#自定義標籤文件Root目錄和後綴
#RESOURCE.tagRoot = htmltag
#RESOURCE.tagSuffix = tag
##### 擴展 ##############
## 內置的方法
#FN.date = org.beetl.ext.fn.DateFunction
##內置的功能包
#FNP.strutil = org.beetl.ext.fn.StringUtil
##內置的默認格式化函數
#FTC.java.util.Date = org.beetl.ext.format.DateFormat
## 標籤類
#TAG.include= org.beetl.ext.tag.IncludeTag
3.4在springmvc.xml的配置文件中配置模版引擎
<!-- beetl config -->
<bean id="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init">
<property name="configFileResource" value="classpath:beetl.properties"/>
</bean>
<!-- beetl視圖解析器 -->
<bean name="beetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
<!-- 多視圖解析器,需要設置viewNames和order -->
<!-- <property name="suffix" value=".btl"/> -->
<property name="suffix" value=".html"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
<property name="order" value="0"/>
<!-- 多GroupTemplate,需要指定使用的bean -->
<!--<property name="config" ref="beetlConfig"/>-->
</bean>
3.5在beetl.properties配置文件中的RESOURCE.root= /路徑下建一個test.html的頁面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
${hello}
</body>
</html>
3.6在controller中return一個數據到前臺頁面。
@Controller
public class TestController {
@RequestMapping(value="/test1")
public ModelAndView test() {
ModelAndView view =new ModelAndView("test");
//view.setViewName("test");
view.addObject("hello", "hello word!!!");
return view;
}
}
如果不瞭解ModelAndView,參考下面這個鏈接:https://blog.csdn.net/qq30211478/article/details/78016155
3.7訪問頁面結果如下