-
项目创建
IDEA选择新建项目,选择Spring Initialize,点击next
设置好包名和Java版本后选择需要添加的依赖后完成创建
-
配置数据库和thymeleaf
在
application.yml
中配置数据库的连接和thymeleafspring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC username: user0 password: 123456 thymeleaf: mode: HTML profiles: active: dev
-
构建基本结构
结构与ssm基本相同,static用来存储静态资源,templates存储界面等模板
-
编写代码测试
在
templates\first.html
中编写一个html文件<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 欢迎! </body> </html>
在
com.llanero.springboot_test.web.IndexController
中控制显示该页面package com.llanero.springboot_test.web; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class IndexController { @GetMapping("/") public String index() { return "first"; } }
-
测试结果