springboot thymeleaf简单整合

最近在学习springboot做一下记录

首先在pom.xml中导入thymeleaf依赖

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

然后是在application.properties中写配置
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html

(注意!!)文件名一定要叫templates 

然后就是在resources中创建文件夹templates(注意文件名不能错)

在templates文件夹中创建html文件

HTML内容我就不贴了 随便写

(笔者在文件夹名字被坑了一把 springboot中thymeleaf默认路径是templates不对的话会路径报错)

然后控制层中写个类调用Controller.java

@RequestMapping(value ="/index" , method = RequestMethod.GET)
	String index() {
		System.out.println("欢迎进入温度管理系统!");
		return "index";
	}

return后面写要返回的页面名称

注意·:Controller类名上要使用注解@Controller

不能使用@restController否则会直接返回返回值里的字段而不是返回到页面


总结·:springboot确实好用但是坑有点多- -

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值