栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot中关于static和templates的注意事项以及webjars的配置

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot中关于static和templates的注意事项以及webjars的配置

1. 默认情况下, 网页存放于static目录下, 默认的"/"指向的是~/resouces/static/index.html文

2. 如果引入了thymeleaf, 则默认指向的地址为~/resouces/templates/index.html

 
 org.springframework.boot
 spring-boot-starter-thymeleaf
 

代码结构:

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";
   }
 
 
 
   
   
   
 
 
 
Hello, BootStarp & WebJars!

4. HTML中引入webjars时, 需导入类似下面的包

 
  org.webjars
  bootstrap
  3.3.7
 
 
  org.webjars
  jquery
  3.1.1
 

5. HTML样例

 
 
 
   
   
   
 
 
 
Hello, BootStarp & WebJars!

6. 结果:

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对考高分网的支持。如果你想了解更多相关内容请查看下面相关链接

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/139044.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号