0
点赞
收藏
分享

微信扫一扫

使用thymeleaf的心路历程

半夜放水 2021-10-09 阅读 29

使用过程遇到如下的问题,网上搜到的解决方法,大都牛头不对马嘴


给大家看一下我项目的结构


controller如下:

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "Hello World";
    }

    @RequestMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("host", "hello world!");
        return "index";
    }

}

html如下:

<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8"/>
    <title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>

最后发现居然是引入jar包的问题
我引入

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

去掉版本好就好了

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

具体为什么,还不是很懂,后续更新。。。

举报

相关推荐

0 条评论