本文章内容主要讲下怎么通过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、访问页面