一、常见的模板引擎
JSP、Velocity、Freemarker、Thymeleaf
1.1.Thymeleaf入门
模板引擎的原理
模板引擎可以看做是一种文件(内容)合成技术,我们可以使用某种模板引擎(Freemarker),使用填充数据,对模板进行合并可以输出响应的文件 , 如: model(数据) + ftl (模板文件) = html(合并成html)
1.1.1.引入jar包
<!--thymeleaf模板-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--如果用到jquery 导入jquery jar包-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;