(三)Maven+SpringBoot整合thymeleaf

11 篇文章 0 订阅
3 篇文章 0 订阅

1、在上文创建的整合项目中,添加依赖

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
 </dependency>

2、在application.yml中添加配置

spring:
  thymeleaf:
    prefix: classpath:/templates/

3、在资源目录resources中新增templates文件夹,用于存放html文件;添加static文件夹,存放静态文件,例如照片、js等

4、创建controller类,测试整合是否成功

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {

	@RequestMapping({"/", "/index"})
	public String index() {
		return "index";
	}
}

5、运行测试,可以选择项目,右键Run As->Spring Boot App或者在xxxAPP.java文件中运行主函数接口

6、运行成功后,命令行会出现如下内容(此处去除了debug日志)

7、浏览器输入 http://localhost:2222/  回车 ,即可访问到templates文件夹下的index.html文件,其中2222为设置的端口地址

SpringBoot系列文章请查看,更多内容正在更新中

(一)Myeclipse2018创建Maven项目

(二)Maven整合SpringBoot

(三)Maven+SpringBoot整合thymeleaf

(四)Maven+SpringBoot+thymeleaf 配置热部署devtools

(五)Maven+SpringBoot整合Bootstrap

(六)Maven+SpringBoot整合Mybatis+SQL Server

(七)SprintBoot项目打包成jar并做成后台运行的服务

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值