springboot中写html,通过SpringBoot访问HTML页面

本文章内容主要讲下怎么通过SpringBoot进入HTML页面

1、首先在pom.xml添加对HTML的相关依赖

/**

* pom.xml文件

*/

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-thymeleaf

org.springframework.boot

spring-boot-maven-plugin

2、在application.yml文件添加SpringBoot相关配置;

spring:

thymeleaf:

prefix: classpath:/templates/

或者在application.properties中添加

spring.thymeleaf.prefix=classpath:/templates/

3、创建HTML文件

/**

* 路径:resources/templates

*/

第一个HTML页面

Hello Spring Boot!!!

4、在Controller里面写跳转HTML页面方法

@Controller //注意这里必须为Controller

public class HelloController {

/**

* 本地访问内容地址 :http://localhost:8080/lmycc/hello

* @param map

* @return

*/

@RequestMapping("/hello")

public String helloHtml(HashMap map) {

map.put("hello", "欢迎进入HTML页面");

return "/index";

}

}

5、访问页面

bc3b9aa399229262c6cb516db986f6d7.png