详解如何配置springboot跳转html页面
本文主要介绍了如何配置springboot跳转html页面,分享给大家,具体如下:
1.首先在pom文件中引入模板引擎jar包,即:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2.在application.properties中配置模板引擎
spring.thymeleaf.prefix=classpath:/templates/
是让controller层到templates文件夹寻找xx.html(src/main/resources/templates)
3.在templates下建立index.html文件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Title</title> </head> <body> <h1>123456789</h1> </body> </html>
4.controller层
package com.example.demo.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * Created by kemp on 2018/8/15. */ @Controller public class MyController { @RequestMapping("/test") public String test(){ return "index"; } }
注意:@controller不是@RestController,使用@RestController会返回“index”字符串
5.在浏览器中地址栏输入:http://localhost:8080/test
到此这篇关于详解如何配置springboot跳转html页面的文章就介绍到这了,更多相关springboot跳转html页面内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
浅析Java中comparator接口与Comparable接口的区别
本文要来详细分析一下Java中Comparable和Comparator接口的区别,两者都有比较的功能,那么究竟有什么区别呢,感兴趣的Java开发者继续看下去吧2016-10-10mybatis-plus多表分页查询最佳实现方法(非常简单)
这篇文章主要给大家介绍了关于mybatis-plus多表分页查询最佳实现方法,文中介绍的方法非常简单,MyBatis-Plus中分页查询是比较方便的,这个功能在网站中也是非常常用的,这方面的知识点是必备的知识点,需要的朋友可以参考下2023-08-08spring-kafka使消费者动态订阅新增的topic问题
这篇文章主要介绍了spring-kafka使消费者动态订阅新增的topic问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-12-12java开发ShardingSphere的路由引擎类型示例详解
这篇文章主要为大家介绍了java开发ShardingSphere的路由引擎类型示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-08-08
最新评论