Spring Boot–模板引擎thymeleaf


	Spring Boot--模板引擎thymeleaf
[编程语言教程]

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

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

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » Spring Boot–模板引擎thymeleaf