最近做一个小功能,一个html单页完成信息展示及操作,前端使用Vue + ElementUI,后端使用springboot提供接口,需要在后端springboot项目中直接访问html页面,这样做比较简单。
1、先写一个springboot基础项目
这里不做介绍,可参考博文:SpringBoot入门教程一:SpringBoot之Hello World
2、resources下新增配置文件application.yml
server:
port: 8080
spring:
mvc:
view:
prefix: /
suffix: .html3、resources下新建static文件夹,新增hello.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>这是一个html页面</title>
</head>
<body>
<h1>springboot访问html页面</h1>
</body>
</html>4、web层调整
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public String index() {
return "hello";
}
}启动springboot, 浏览器访问http://127.0.0.1:8080/hello

版权声明:本文为angellee1988原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。