运随心转,相由心生
需要一个百里香来实现,不不,是thymeleaf来实现。
1、添加依赖包 在pom.xml文件里面
<dependency>
<grounpId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、配置这个模板
在application.properties里面配置
spring.thymeleaf.prefix=classpath:/templates/
3、在templates文件夹里面新建一个html5文件
<!DOCTYPE html>
<html lang="utf-8">
<head>
<meta charset="UTF-8">
<title>springboot+mybatis的增删改查</title>
</head>
<body>
<h1>springboot+mybatis的增删改查</h1>
</body>
</html>
4、新建一个java文件
package com.control;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/index")
public class JspControl {
@RequestMapping("/index")
public String index(){
return "index";
}
}
尝试一、运行程序,打开浏览器,输入http://localhost:8080/项目名称/jsp/index/
输入回车
突然报错
原来是我的入口程序放错了位置......
记住,不需要项目名称的,直接http://localhost:8080/jsp/index/
总结: 需要thymeleaf依赖实现,在pom.xml文件中导入依赖,然后在application.properties文件里面配置thymeleaf依赖的基础信息;在java中设置一下访问html的路径;