码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot--模板引擎thymeleaf

时间:2020-11-24 13:01:28      阅读:18      评论:0      收藏:0      [点我收藏+]

标签:void   too   启动   tap   资源文件   ppi   常见   pre   star   

1.引入依赖

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

 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <scope>runtime</scope>
  <optional>true</optional>
 </dependency>
</dependencies>

2.创建启动器

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

3.创建controller

@Controller
public class IndexController {
    @GetMapping("nav")
    public String index(@RequestParam(name = "name", required = false) String name, Model model) {
        model.addAttribute("name", name);
        return "index";
    }
}

4.资源文件夹下创建html文件

resource下创建templates目录,目录下创建html文件

5.测试结果

常见错误

Cannot find template location: classpath:/templates/ 检查打包是否pom(不要)

Spring Boot--模板引擎thymeleaf

标签:void   too   启动   tap   资源文件   ppi   常见   pre   star   

原文地址:https://www.cnblogs.com/KingJA/p/14012666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!