<强> 1。默认情况下,网页存放于静态目录下,默认的“/敝赶虻氖莮/资源/静态/index . html文强>
<强> 2。如果引入了thymeleaf,则默认指向的地址为~/资源/模板/index . html 强>
& lt; dependency> & lt; groupId> org.springframework.boot & lt; artifactId> spring-boot-starter-thymeleaf & lt;/dependency>
代码结构:
<强> 3。在引入thymeleaf后,如果仍需要访问~/静态/索引。html,则可以使用重定向强>
返回“重定向:/index . html”
代码样例:
进口org.springframework.stereotype.Controller; 进口org.springframework.ui.Model; 进口org.springframework.web.bind.annotation.GetMapping; 进口org.springframework.web.bind.annotation.RequestMapping; 进口javax.servlet.http.HttpServletRequest; 进口javax.servlet.http.HttpServletResponse; 进口java.io.IOException; @ controller 公开课HomeCtrl { @GetMapping (“/? 公共主页字符串(模型模型,HttpServletRequest请求,HttpServletResponse响应)抛出IOException { 返回“/指数”; } @RequestMapping("/静态”) 公共字符串navigatorToStatic () { 返回“重定向:/static.html”; }
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt;脚本src=" https://www.yisu.com/zixun/webjars/jquery/3.1.1/jquery.min.js "祝辞& lt;/script> & lt;脚本src=" https://www.yisu.com/zixun/webjars/bootstrap/3.3.7/js/bootstrap.min.js "祝辞& lt;/script> & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/webjars/bootstrap/3.3.7/css/bootstrap.min.css " rel=巴獠縩ofollow”rel=巴獠縩ofollow”/比; & lt;/head> & lt; body> & lt; div类="容器"祝辞& lt; br/比; & lt; div class="警惕alert-success”比; 你好,& lt; strong> BootStarp,WebJars ! & lt;/strong> & lt;/div> & lt;/div> & lt;/body> & lt;/html>
<强> 4。HTML中引入webjars时,需导入类似下面的包强>
& lt; dependency> & lt; groupId> org.webjars & lt; artifactId> bootstrap & lt; version> 3.3.7 & lt;/dependency> & lt; dependency> & lt; groupId> org.webjars & lt; artifactId> jquery & lt; version> 3.1.1 & lt;/dependency>
<强> 5。HTML样例强>
& lt; !DOCTYPE html> & lt; html> & lt; head> & lt;脚本src=" https://www.yisu.com/zixun/webjars/jquery/3.1.1/jquery.min.js "祝辞& lt;/script> & lt;脚本src=" https://www.yisu.com/zixun/webjars/bootstrap/3.3.7/js/bootstrap.min.js "祝辞& lt;/script> & lt;链接rel="样式表" href=" https://www.yisu.com/zixun/webjars/bootstrap/3.3.7/css/bootstrap.min.css " rel=巴獠縩ofollow”rel=巴獠縩ofollow”/比; & lt;/head> & lt; body> & lt; div类="容器"祝辞& lt; br/比; & lt; div class="警惕alert-success”比; 你好,& lt; strong> BootStarp,WebJars ! & lt;/strong> & lt;/div> & lt;/div> & lt;/body> & lt;/html>
<强> 6。结果:强>
<强>总结强>
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接