springboot之thymeleaf模板引擎章节
来源:互联网 发布:装修省钱 知乎 编辑:程序博客网 时间:2024/05/17 04:35
1、根据上章步骤构建web项目;
2、在pom.xml配置文件中添加thymeleaf依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3、在application.properties文件中配置thymeleaf的相关信息
spring.thymeleaf.prefix=/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
4、编写Controller层
@Controller
public class HelloWorld {
@RequestMapping("/hello")
public String helloHtml(HashMap<String,Object> map){
map.put("user","zhangsan");
return"pages/index";
}
}
注:记住一定不要用RestController注解
5、在templates下面新建pages文件夹,并在其下面新建index.html文件
6、index.html文件内容参考如下:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello!, ' + ${user} + '!'" >lisi</p>
</body>
</html>
注:一定要在html页面中引入thymeleaf 标签:<html xmlns:th="http://www.thymeleaf.org">
7、启动springboot类,并访问:http://localhost:8080/hello
- springboot之thymeleaf模板引擎章节
- springboot之模板引擎 --- thymeleaf
- SpringBoot Thymeleaf 模板引擎
- springboot webmvc thymeleaf 模板引擎
- SpringBoot使用thymeleaf模板引擎
- SpringBoot整合模板引擎Thymeleaf
- java springboot Thymeleaf模板引擎
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- SpringBoot学习-支持thymeleaf模板引擎
- SpringBoot-07引擎模板thymeleaf和freemarker的使用
- thymeleaf模板引擎之基本语法
- SpringBoot-thymeleaf模板集成
- springboot整合thymeleaf模板
- SpringBoot整合thymeleaf模板
- SpringBoot集成Thymeleaf模板
- Thymeleaf 模板引擎
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- 在java中 变量之间是如何赋值的
- Linux Shell 特殊变量
- DAG动规 uva
- python使用wordcloud创建词云
- Java JNI调用so动态链接库
- springboot之thymeleaf模板引擎章节
- Android进阶#(4/12)HTTP网络请求_HTTP请求原理
- tomcat 修改项目部署路径
- 安装Ubuntu时遇到“无法将grub-efi-amd64-signed软件包安装到/target/中”或“安装程序向硬盘复制文件时遇到错误”
- VI打开和编辑多个文件的命令
- XML生成(三):JDOM生成
- qt-opensource-windows-x86-vs2010-4.8.6 + qt-creator-windows-opensource-2.8.0
- kubernetes--资源管理
- 为IOS创建阿里云IPV6隧道地址