zoukankan      html  css  js  c++  java
  • SpringBoot之前端文件管理

    WebJars能使Maven的依赖管理支持OSS的JavaScript库/CSS库,比如jQuery、Bootstrap等。 

    (1)添加js或者css库 
    pom.xml 

    Xml代码  收藏代码
    1. <dependency>  
    2.     <groupId>org.webjars</groupId>  
    3.     <artifactId>bootstrap</artifactId>  
    4.     <version>3.3.7-1</version>  
    5. </dependency>  
    6. <dependency>  
    7.     <groupId>org.webjars</groupId>  
    8.     <artifactId>jquery</artifactId>  
    9.     <version>3.1.1</version>  
    10. </dependency>  



    src/main/resources/static/demo.html 

    Html代码  收藏代码
    1. <html>  
    2.     <head>  
    3.         <script src="/webjars/jquery/3.1.1/jquery.min.js"></script>  
    4.         <script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>  
    5.         <title>WebJars Demo</title>  
    6.         <link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />  
    7.     </head>  
    8.     <body>  
    9.         <div class="container"><br/>  
    10.             <div class="alert alert-success">  
    11.                 <href="#" class="close" data-dismiss="alert" aria-label="close"</a>  
    12.                 Hello, <strong>WebJars!</strong>  
    13.             </div>  
    14.         </div>  
    15.     </body>  
    16. </html>  



    启动应用后可以看到以下log: 

    引用
    2017-02-09 13:52:48.117  INFO 6188 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]



    启动应用访问 http://localhost:8080/demo.html 
     

    (2)省略版本号 

    很少在代码中硬编码版本号,所以需要隐藏它。 

    pom.xml添加webjars-locator 
    org.springframework.web.servlet.resource.WebJarsResourceResolver 

    Java代码  收藏代码
    1. <dependency>  
    2.     <groupId>org.webjars</groupId>  
    3.     <artifactId>webjars-locator</artifactId>  
    4.     <version>0.31</version>  
    5. </dependency>  



    src/main/resources/static/demo.html 

    引用
    <script src="/webjars/jquery/3.1.1/jquery.min.js"></script> 
    <script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script> 
    <title>WebJars Demo</title> 
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" /> 

    -> 

    <script src="/webjars/jquery/jquery.min.js"></script> 
    <script src="/webjars/bootstrap/js/bootstrap.min.js"></script> 
    <title>WebJars Demo</title> 
    <link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css" />



    启动应用再次访问 http://localhost:8080/demo.html 结果和上边一样。 

    引入的开源JavaScript库/CSS库将会以jar的形式被打包进工程! 
    spring-boot-demo1-0.0.1-SNAPSHOT.jarBOOT-INFlib 

    引用
    bootstrap-3.3.7-1.jar 
    └─ META-INF 
        └─ resources 
            └─ webjars 
                └─ bootstrap 
                    └─ 3.3.7-1 
                        ├─ css 
                        |   ├─ bootstrap.min.css 
                        |   ├─ bootstrap.min.css.gz # Gzip文件 
                        ...



    引用
    jquery-3.1.1.jar 
    └─ META-INF 
        └─ resources 
            └─ webjars 
                └─ jquery 
                    └─ 3.1.1 
                        ├─ jquery.min.js 
                        ...
  • 相关阅读:
    POJ 2240 Arbitrage spfa 判正环
    POJ 3259 Wormholes spfa 判负环
    POJ1680 Currency Exchange SPFA判正环
    HDU5649 DZY Loves Sorting 线段树
    HDU 5648 DZY Loves Math 暴力打表
    HDU5647 DZY Loves Connecting 树形DP
    CDOJ 1071 秋实大哥下棋 线段树
    HDU5046 Airport dancing links 重复覆盖+二分
    HDU 3335 Divisibility dancing links 重复覆盖
    FZU1686 神龙的难题 dancing links 重复覆盖
  • 原文地址:https://www.cnblogs.com/smiler/p/6857213.html
Copyright © 2011-2022 走看看