【问题标题】:webjars directory on the client side is almost empty客户端的 webjars 目录几乎是空的
【发布时间】:2016-09-29 11:24:42
【问题描述】:

我的应用程序启动后,我只能在客户端的 webjars 目录中看到几个 js 文件:

  • webjars/jquery/3.1.1/jquery.js
  • webjars/jquery/3.1.1/jquery.min.js

但我没有看到任何其他必要的 js 文件

有我的配置和代码:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>


    <groupId>com.gmail.user</groupId>
    <artifactId>solo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <jstl.version>1.2</jstl.version>
        <gson.version>2.7</gson.version>
        <bootstrap.version>3.3.7</bootstrap.version>
        <jquery.version>3.1.1</jquery.version>
        <jquery-ui.version>1.12.1</jquery-ui.version>
        <jquery-datatables.version>1.10.12</jquery-datatables.version>
        <jquery-dateFormat.version>1.0.2</jquery-dateFormat.version>
        <momentjs.version>2.15.0</momentjs.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.32</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>${bootstrap.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>${jquery.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-ui</artifactId>
            <version>${jquery-ui.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>datatables</artifactId>
            <version>${jquery-datatables.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-dateFormat</artifactId>
            <version>${jquery-dateFormat.version}</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>momentjs</artifactId>
            <version>${momentjs.version}</version>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>${gson.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Application.java

package com.gmail.user;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application{

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

application.properties

spring.datasource.url=jdbc:mysql://localhost/solo
spring.datasource.username=root
spring.datasource.password=1
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

logging.level.org.hibernate.SQL=debug
logging.level.org.springframework.web:INFO

spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false

_parent.html

    <script type="text/javascript" src="/webjars/jquery/3.1.1/jquery.min.js"/>
    <script src="/webjars/jquery-ui/1.12.1/jquery-ui.min.js"/>
    <link rel="stylesheet" type="text/css" href="/webjars/jquery-ui/1.12.1/jquery-ui.min.css"/>
    <script type="text/javascript" charset="utf8" src="/webjars/datatables/1.10.12/js/jquery.dataTables.js"/>
    <link rel="stylesheet" type="text/css" href="/webjars/datatables/1.10.12/css/jquery.dataTables.css"/>
    <script src="/webjars/jquery-dateFormat/1.0.2/jquery-dateFormat.js"/>

    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap-theme.min.css"/>>
    <script src="/webjars/bootstrap/3.3.7/js/bootstrap.min.js"/>

    <script src="/webjars/momentjs/2.15.0/moment.js"/>

【问题讨论】:

    标签: java jquery maven spring-boot webjars


    【解决方案1】:

    我想我发现了我的错误。 我不得不用&lt;/script&gt; 关闭&lt;script&gt; 标签,但不用/&gt;

    这是错误的:

    <script type="text/javascript" src="/webjars/jquery/3.1.1/jquery.min.js"/>
    

    这是正确的:

    <script type="text/javascript" src="/webjars/jquery/3.1.1/jquery.min.js"></script>
    

    但我还是不明白为什么文件 jquery.js 和 jquery.min.js 上传成功。

    【讨论】:

    • 这就是浏览器解析事物的方式。 HTML 中的第一个开始标记确实包含错误,因为它以/&gt; 结尾。但这不是一个大问题。浏览器可以加载src指定的文件就好了。在那之后,浏览器完全被搞糊涂了,因为 HTML 的其余部分在 inside 脚本元素中,它被视为(非常糟糕的)JavaScript 而不是 HTML。这一直持续到第一个结束标记,之后解析正常恢复。
    • 感谢您的解释。
    • 有谁知道如何告诉 webjars 中的目录?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多