我的观点似乎没有看到我的 css,js。我正在使用弹簧靴和百里香叶

Posted

技术标签:

【中文标题】我的观点似乎没有看到我的 css,js。我正在使用弹簧靴和百里香叶【英文标题】:My view does not seem to see my css,js. Am using spring boot and thymeleaf 【发布时间】:2015-10-02 04:31:38 【问题描述】:

这是我的 login.html 文件(视图)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
<title>The Login Page</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script type="application/x-javascript" th:inline="javascript"> addEventListener("load", function()  setTimeout(hideURLbar, 0); , false); function hideURLbar() window.scrollTo(0,1);  </script>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,400,300,600,700' media="screen" rel='stylesheet' type='text/css' />
    <link rel="stylesheet" th:href="@/css/style.css" media="screen" href="../public/css/style.css" />
   </head>
   <body>

             <!--  start-main -->
            <div class="container-fluid" style="border: 1px solid red;">
                <!--start of the login form-->
                <div class="login-form">
                    <div class="head">
                        <img th:src ="@/images/mem2.jpg" src="../public/images/mem2.jpg" />

                    </div>
                    <form action="#" method="post" th:action="@/login" th:object="$user">
                        <li>
                            <input type="text" class="text" name="username" placeholder="Username" th:field="*username" onfocus="this.value = '';" onblur="if (this.value == '') this.value = 'Username';" /><a href="#" class=" icon user" ></a>
                            <p th:if="$#fields.hasErrors('username')" th:errors="*username">Username Error</p>
                        </li>
                        <li>
                            <input type="password"  name="password" placeholder="Password" th:field="*password" onfocus="this.value = '';" onblur="if (this.value == '') this.value = 'Password';" /><a href="#" class=" icon lock"></a>
                            <p th:if="$#fields.hasErrors('password')" th:errors="*password">Password Error</p>
                        </li>
                        <div class="p-container">
                                    <label class="checkbox"><input type="checkbox" name="checkbox" checked="checked" /><i></i>Remember Me</label>
                                    <input type="submit" value="SIGN IN" />
                                <div class="clear"> </div>
                        </div>
                    </form>
                </div>
                <!--//End-login-form-->
            <!--start-copyright-->
            <div class="copy-right">
                        <p th:include="footer :: footer"></p>
                </div>
                <!--//end-copyright-->
        </div>
  </body>
  </html>

在这个 login.html 中,我使用 thymeleaf 来引用 css、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.social.manager</groupId>
<artifactId>Social-Manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>SocialManagement</name>
<description>Social Management App</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</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-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-facebook</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-linkedin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-twitter</artifactId>
    </dependency>

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

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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


</project>

我需要帮助,我已经浏览过有关此主题的其他帖子,但似乎没有一个有效。

我的css文件放在src/main/resources/public下

src/main/resources/public/css

src/main/resources/public/js

src/main/resources/public/images

我的模板文件位于:

src/main/resources/模板

【问题讨论】:

【参考方案1】:

如果没有资源处理程序处理这些路径,@/css/style.css 将获得您在源代码的src/main/webapp/css/style.css 中拥有的文件;它与您最终的战争包的文件夹结构不同。

默认的maven war打包配置会将src/main/resources的内容放入WEB-INF/classes/

【讨论】:

以上是关于我的观点似乎没有看到我的 css,js。我正在使用弹簧靴和百里香叶的主要内容,如果未能解决你的问题,请参考以下文章

Instruments Leaks - 不显示我的源代码

TensorFlow-gpu 似乎没有看到我的 gpu

laravel 8 没有加载 css 和 js/bootstrap

Laravel 包括 css、js 使用 ssl

JS 函数未定义 Chrome 扩展 Popup.js

使用 Chrome Devtools 调试 CSS 动画