通过SpringBoot进入HTML页面
2018-04-06 15:15
369 查看
1、首先在pom.xml添加对HTML的相关依赖
2、在application.yml文件添加SpringBoot相关配置
3、创建HTML文件
4、在Controller里面写跳转HTML页面方法
5、访问页面
好了,这样就可以通过SpringBoot正常访问HTML页面了,快去试试吧!
/** * pom.xml文件 */ <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>**
2、在application.yml文件添加SpringBoot相关配置
spring: thymeleaf: prefix: classpath:/templates/
3、创建HTML文件
/** * 路径:resources/templates */ <!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"/> <title>第一个HTML页面</title> </head> <body> <h1>Hello Spring Boot!!!</h1> <p th:text="${hello}"></p> </body> </html>
4、在Controller里面写跳转HTML页面方法
@Controller //注意这里必须为Controller public class HelloController { /** * 本地访问 http://localhost:8080/helloboot * @param map * @return */ @RequestMapping("/hello") public String helloHtml(HashMap<String, Object> map) { map.put("hello", "欢迎进入HTML页面"); return "/index"; } }
5、访问页面
好了,这样就可以通过SpringBoot正常访问HTML页面了,快去试试吧!
相关文章推荐
- springboot vue.js axios.js ajax请求纯HTML页面传值
- springboot跳转html页面
- spring boot + html 页面
- springboot-thymeleaf(html页面跳转)
- Spring Boot使用freemarker并且生成静态html页面
- springboot + freemarker 返回html页面基本操作(初学者)
- [spring boot] 用 thymeleaf模板开发html页面
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- SpringBoot直接访问HTML页面
- springboot开发日志(2): 找不到html页面
- Spring boot项目中展示HTML页面效果
- Spring-boot 设置首页跳转到Html页面
- Springboot怎么访问html页面
- thymeleaf :springboot整合mybatis的web项目中使用html而不是jsp当页面渲染
- spring boot 使用velocity、freeMarker模板创建html页面返回给前端
- springboot整合freemarker生成静态HTML页面
- springboot如何使用thymeleaf模板访问html页面
- springboot中通过cors协议解决跨域问题
- start.spring.io快速搭建springboot项目页面解析介绍
- spring boot之集成页面