使用Spring boot访问HTML页面
2020-07-14 04:56
337 查看
最近在实例应用Spring boot 时,访问前段页面一直报404错误,为了防止以后继续跳这个坑,还是写个文章记录下来吧。
本文章主要讲怎么通过spring boot 进入HTML页面。
1.pom文件的依赖:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--mybatis起步依赖--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!-- MySQL连接驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!--测试的起步依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 配置使用redis启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!--添加热部署的依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- 注意必须要引入这个依赖!!!--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies>
2.配置文件
在application.yml文件添加SpringBoot的相关配置,
注:也可以不写该配置,默认读取的是resources/templates/下的页面,下方配置读取的是resources/resources/下的页面
spring: thymeleaf: prefix: classpath:/resources/
3.创建页面
<!-- classpath:resources/resources 若第2步没有配置,则此文件的 classpath 应为:resources/templates --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> this is index html resources </body> </html>
4 写跳转方法
@Controller public class MapperController { /** * 访问路径为:http://localhost:8080/getIndex * @return */ @RequestMapping("/getIndex") public String getIndex(){ System.out.println("开始访问index页面"); return "index"; } }
5.访问页面
这样就可以成功访问html页面了。
相关文章推荐
- 使用html页面实现简单的算法并通过百度网盘实现访问
- 使用WebMvcConfigurationSupport无法访问html页面原因分析
- 使用UrlRewritingNet重写url以.html的伪静态页面后,真实的.html无法访问的解决方法
- MFC使用WebBrowser控件访问HTML页面DOM
- 如何使用Fiddler实现跨域访问(把自己做的静态HTML页面域名变成api.bing.com)
- springboot如何使用thymeleaf模板访问html页面
- Windows 下xampp的安装使用以及本地静态页面的访问(HTML+CSS+JS)
- 使用js实现多个html页面访问同一个常量
- 使用springboot项目直接访问html页面犯的傻事
- 使用NodeVisitor访问HTML页面的TAG
- 如何使用Fiddler实现跨域访问(把自己做的静态HTML页面域名变成api.bing.com)
- html页面中使用thymeleaf模板直接访问后台service
- .net生成静态HTML页面怎么限制用户访问?
- 如何在多个页面使用同一个HTML片段
- 怎么配置spring访问静态html页面
- 怎样使.aspx的页面在访问时映射成.html的页面
- 在Silverlight页面里显示HTML的免费控件下载(附使用方法代码)
- 使用JavaScript实现访问本站点任何页面都加载Frame的一种实现方式
- Javascript访问Cookie的四个基本方法无论是在创建页面还是构建对象都会使用到,单独拿出来备用:
- 使用xmldom在服务器端生成静态html页面