1、在pom.xml添加以下jar依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、添加展示页面:thymeleaf模板引擎默认会加载classpath:/templates/目录下的后缀名为"html"的文件,所以添加以下目录及文件:
public目录下的文件默认为系统欢迎页面,启动系统访问http://localhost:8080/则会直接跳到欢迎页面;
添加action类:
@Controller
@RequestMapping("/boot")
public class Main {
@RequestMapping("/index")
public String main(Model model){
model.addAttribute("name", "spring boot");
return "index";
}
}
直接访问http://localhost:8080/boot/index,则会直接跳转到templates/in