java 集成enjoy模板引擎
时间: 2023-10-22 19:08:49 浏览: 44
集成Enjoy模板引擎需要以下步骤:
1. 在pom.xml文件中添加Enjoy的依赖:
```
<dependency>
<groupId>org.beetl</groupId>
<artifactId>beetl-framework-starter</artifactId>
<version>2.8.0.RELEASE</version>
</dependency>
```
2. 配置Enjoy的模板路径和后缀名,在application.properties中添加如下配置:
```
beetl.templatesPath=classpath:/templates/
beetl.suffix=.html
```
3. 创建模板文件,例如index.html:
```
<!DOCTYPE html>
<html>
<head>
<title>Enjoy Template Engine</title>
</head>
<body>
<h1>Hello ${name}!</h1>
</body>
</html>
```
4. 在Controller中使用Enjoy渲染模板:
```
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class IndexController {
@GetMapping("/")
public String index(Model model) {
model.addAttribute("name", "Enjoy");
return "index";
}
}
```
5. 运行程序,访问http://localhost:8080/,即可看到渲染后的页面。
Enjoy模板引擎集成完成!