所以我正在使用 Thymeleaf 构建一个 Spring Boot 项目,其文件结构如下:
src
|_main
|_ java
|_ resources
|_ static
|_ images
|_ image.jpg
|_ js
|_ imagetodata.js
|_ templates
|_ image_history.html
在 HTML 文件中,我写了
<script th:src="@{js/imagetodata.js}"></script>
和 <img id="imageInput" th:src="@{images/image.jpg}" alt="Image">
,但控制台显示“404 Not Found”或“net:: ERR_ABORTED 404”。
我应该怎么做才能解决这个问题?我尝试了很多方法和URL,但问题仍然存在,而且我没有使用Spring Security之类的东西。这是我的依赖项:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
implementation 'commons-io:commons-io:2.11.0'
implementation 'commons-fileupload:commons-fileupload:1.4'
runtimeOnly 'mysql:mysql-connector-java'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
你可以尝试在js和图片前添加/。
喜欢:-
<script th:src="@{/js/imagetodata.js}"></script>
<img id="imageInput" th:src="@{/images/image.jpg}" alt="Image">