Springboot整合thymleaf

我在整合的过程中遇到了好多坑,还好,一一解决,如果你也遇到坑了,不要怕,看过来

1.在pom中引入依赖

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

2.在引入配置文件方面

thymeleaf:
    spring.thymeleaf.prefix=classpath:/templates/
    spring.thymeleaf.check-template-location=true
    spring.thymeleaf.suffix=.html
    spring.thymeleaf.encoding=UTF-8
    spring.thymeleaf.content-type=text/html
    spring.thymeleaf.mode=HTML5
    spring.thymeleaf.cache=false
注意不要有空格

3.后台路径上

@Controller
public class LoginController extends BaseController {

    @RequestMapping(value = "/save")
    public String save(String mol,Model model){
        model.addAttribute("testId",mol);
        return "index";
    }
}
不要用@RestController,RequestMapping里边不要有指定这是get方法,或者post方法的那个什么什么

4.在页面上如果你发现你用不了thymleaf的标签,你就要在html开头

引入<html xmlns:th="http://www.thymeleaf.org">

5.如果找不到404,看看自己的路径

6.ok了,

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值