springboot访问html文件

Posted mytdbky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot访问html文件相关的知识,希望对你有一定的参考价值。

1  在pom.xml加入


<parent>

   <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.2.RELEASE</version>

</parent>

<dependencies>

   <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

        <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot</artifactId> <version>1.2.0</version>

       </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>

       <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>

       <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

</dependencies>

2 在resources\templates\hello.html

3 在Controller中加入

@RequestMapping("/hello")
    public String helloHtml(HashMap<String,Object> map){
        map.put("hello","HelloWord"); return"/hello"; 
}
 

启动,然后输入localhost:8080/hello

会跳转到页面

注意:必须加入thymeleaf包,不然找不到



以上是关于springboot访问html文件的主要内容,如果未能解决你的问题,请参考以下文章

学习小片段——springboot 错误处理

Spring boot:thymeleaf 没有正确渲染片段

springboot templates 下的HTML访问不到

SpringBoot目录文件结构和官方推荐的目录规范静态资源访问

SpringBoot浏览器直接访问html

springboot访问html文件