springboot通过jar包方式引入bootstrap

编程知识 行业动态 更新时间:2024-06-13 00:22:36

一、springboot引入bootstrap的两种方式

  1. SpringBoot结合前端有主要有两种方法,一种是在static里面直接加入下载的bootstrap中的css或js;另一种是引入webjars,以jar包的形式加入项目。
  2. 手动在static中引入bootstrap需要自己去手动下载bootstrap,而引入webjars通过jar包方式就需要配置pom.xml即可。
  3. webjars方式引入bootstrap,实际上就是通过webjars方式管理前端静态资源的方式,具体的可以参考:https://www.jianshu/p/66d...
  4. WebJars官网找到项目所需的依赖,例如在pom.xml引入 jQuery、BootStrap前端组件等。

二、webjars方式引入

  1. 新建一个SpringBoot Web项目。然后在pom文件引入webjars的jar,pom文件代码如下:

           <dependency>
               <groupId>org.webjars</groupId>
               <artifactId>bootstrap</artifactId>
               <version>3.3.5</version>
           </dependency>
           <dependency>
               <groupId>org.webjars</groupId>
               <artifactId>jquery</artifactId>
               <version>3.1.1</version>
           </dependency>
  2. 然后我们观察下项目的依赖包:
  3. 然后在src/main/resources/templates文件下新建index.html,代码如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="UTF-8">
       <title>Dalaoyang</title>
       <link rel="stylesheet" href="/webjars/bootstrap/3.3.5/css/bootstrap.min.css" />
       <script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
       <script src="/webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div class="container"><br/>
       <div class="alert alert-success">
           <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
           <h3>index首页</h3>Hello, <strong>springboot and bootstrap!!!</strong>
       </div>
    </div>
    </body>
    </html>
  4. 引入的bootstrap包的路径可以通过官网进行查看:

  5. 配置结束,启动项目,访问http://localhost:8888/

更多推荐

springboot通过jar包方式引入bootstrap

本文发布于:2023-04-02 19:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/3d4b65611730af49034bd86f0f11a373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   springboot   jar   bootstrap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!