1. 默认情况下, 网页存放于static目录下, 默认的"/"指向的是~/resouces/static/index.html文
成都创新互联公司专业为企业提供泉州网站建设、泉州做网站、泉州网站设计、泉州网站制作等企业网站建设、网页设计与制作、泉州企业网站模板建站服务,十余年泉州做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
2. 如果引入了thymeleaf, 则默认指向的地址为~/resouces/templates/index.html
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
代码结构:
3.在引入thymeleaf后, 如果仍需要访问~/static/index.html, 则可以使用重定向
return "redirect:/index.html"
代码样例:
import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Controller public class HomeCtrl { @GetMapping("/") public String homePage(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException { return "/index"; } @RequestMapping("/static") public String navigatorToStatic() { return "redirect:/static.html"; }
<!DOCTYPE html> <html> <head> <script src="webjars/jquery/3.1.1/jquery.min.js"></script> <script src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" /> </head> <body> <div class="container"><br/> <div class="alert alert-success"> Hello, <strong>BootStarp & WebJars!</strong> </div> </div> </body> </html>
4. HTML中引入webjars时, 需导入类似下面的包
<dependency> <groupId>org.webjars</groupId> <artifactId>bootstrap</artifactId> <version>3.3.7</version> </dependency> <dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.1.1</version> </dependency>
5. HTML样例
<!DOCTYPE html> <html> <head> <script src="webjars/jquery/3.1.1/jquery.min.js"></script> <script src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" /> </head> <body> <div class="container"><br/> <div class="alert alert-success"> Hello, <strong>BootStarp & WebJars!</strong> </div> </div> </body> </html>
6. 结果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对创新互联的支持。如果你想了解更多相关内容请查看下面相关链接
网站标题:SpringBoot中关于static和templates的注意事项以及webjars的配置
文章出自:https://www.cdcxhl.com/article44/jdopee.html
成都网站建设公司_创新互联,为您提供响应式网站、App设计、、外贸建站、动态网站、商城网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联