博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 2.0 整合Thymeleaf 模板引擎
阅读量:7179 次
发布时间:2019-06-29

本文共 2411 字,大约阅读时间需要 8 分钟。

本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎

1. 创建项目

 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序

 

3. 填写项目配置信息

4. 添加Web 模块

5. 添加thymeleaf 模块

 

 6. 项目保存路径

7. POM.xml 添加thymeleaf依赖

4.0.0
com.xingyun
srping-boot-with-thymeleaf-sample
0.0.1-SNAPSHOT
jar
srping-boot-with-thymeleaf-sample
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin

8. 配置application.properties

spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTMLspring.thymeleaf.encoding=UTF-8spring.thymeleaf.servlet.content-type=text/html# 关闭缓存,即时刷新,上线生产环境需改成truespring.thymeleaf.cache=false

9. 创建模板文件

index.html

    
Titlethis is index.html

welcome.html

    
Titlethis is welcome.html

10.创建Controller

package com.xingyun.srpingbootwiththymeleafsample;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class HomeController {    @GetMapping(value = "/")    public String index(){        return "/views/index";    }    @GetMapping(value = "/welcome")    public String welcome(){        return "/views/welcome";    }}

11. 访问 

12. 访问

 

转载地址:http://ifszm.baihongyu.com/

你可能感兴趣的文章
centos6.x使用dd命令制作u盘启动
查看>>
如何使用Wireshark抓包
查看>>
mysql 时间函数用法 集合
查看>>
技术宅男既要提升编程技术也要加强沟通能力
查看>>
开源计划--格瓦拉梦想(GUEVARA‘S DREAM)
查看>>
show full columns 和 checking privileges的说明
查看>>
电信网络拓扑图自动布局之总线
查看>>
数据库启动时报ORA-00845错误解决方法
查看>>
查询阿里云存储文件并导出excle 保存到本地
查看>>
WebService-—调用第三方提供的webService服务
查看>>
LVM报错:resize2fs: Bad magic number in super-block
查看>>
从开发到部署会用到的 Docker 命令
查看>>
access数据库转mysql数据库
查看>>
CISCO服务器配置RAID步骤
查看>>
利用makefile文件编译c++源文件
查看>>
VS 0xC0000005 运行错误分析
查看>>
ASP.NET中TextBox控件设置ReadOnly="true"后台取不到值
查看>>
找出Java进程ID pid的N种方法
查看>>
SSH和SFTP简介
查看>>
借助JRebel使Tomcat支持热部署
查看>>