springboot訪問html文件

1  在pom.xml加入html


<parent> java

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

</parent> web

<dependencies>spring

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

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

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

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

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

</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包,否則找不到

相關文章
相關標籤/搜索