这是一个国产的,
超过thymeleaf性能十倍的模板引擎,
没有理由不学会它!
- 我们创建一个springboot项目
- 在项目中pom文件中加入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl-framework-starter</artifactId>
<version>1.2.33.RELEASE</version>
</dependency>
3.分别创建IndexController, index.html, show1.html, show2.html, index.css文件如图
代码分别为:
IndexController
@Controller
public class IndexController {
@GetMapping(path = {
"", "/", "/index"})
public ModelAndView index() {
Map<String, Object> data = new HashMap<>(2);
data.put("name", "HelloBeetl");
data.put("now", LocalDateTime.now().toString());
return new ModelAndView("index.html", data);
}
private static String[] contents =
("绿蚁浮觞香泛泛,黄花共荐芳辰。\n清霜天宇净无尘。\n登高宜有赋,拈笔戏成文。\n可奈园林摇落尽,悲秋意与谁论。\n眼中相识几番新。\n龙山高会处,落帽定何人。").split("\n");
private static Random random = new Random();
@GetMapping(path = "show1")
public String showOne(Model model) {
model.addAttribute("title", "清平调词三首");
model.addAttribute("content", contents[random.nextInt(6)