1.修改端口80
想要通过ip直接访问到主页,就要使用默认的80端口
# 端口号和上下文路径
server:
port: 80
servlet:
context-path: /
2.引入pom依赖
<!-- 访问html文件依赖begin -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3.设置模板前缀
如果你要转到的页面是在static目录中的,也可以将thymeleaf修改为static
spring:
thymeleaf:
prefix: classpath:/thymeleaf/
4.编写controller类
编写一个IndexController 类,其中index.html是直接在thymeleaf目录下
@Controller
public class IndexController {
@RequestMapping("/")
public String index(){
return "index";
}
}
到此运行即可直接通过ip来访问index.html了