私は問題を抱えており、何時間も解決を試みてきましたが成功しませんでした。
Thymeleafを使用してSpring Bootアプリを作成しています。一般的に、index.htmlページにロゴを配置する必要がありますが、まったく表示されません。thymeleafタグの有無にかかわらず、さまざまなuri構成(コードスニペットなど)を試しましたが、どれも機能しませんでした。他のthymeleaf(例:条件文など)タグは正常に機能します-私はそれをテストしましたので、依存関係は原因ではありません。
かつて、jspビューを使用してアプリを作成しましたが、画像に問題はありませんでした。
あなたはどう思いますか、何か不足していますか?
プロジェクト構造
src
|_main
|_ java
|_ resources
|_ static
|_ images
|_ logo.png
|_ templates
|_ index.html
index.html
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head"></head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-light"> <!--style="background-color: blueviolet"-->
<div class="container">
<a class="navbar-brand">
<img th:src="@{~/images/logo.png}">
MyApplication
</a>
</div>
</nav>
<img th:src="@{~/static/images/logo.png}">
<img th:src="@{~/images/logo.png}">
<img th:src="@{//static/images/logo.png}">
<img th:src="@{//images/logo.png}">
<img th:src="@{/static/images/logo.png}">
<img th:src="@{static/images/logo.png}">
<img th:src="@{/resources/static/images/logo.png}">
<img th:src="@{resources/static/images/logo.png}">
<img th:src="@{//static/images/logo.png}">
<img th:src="@{//static/images/logo.png}">
<img th:src="@{//resources/static/images/logo.png}">
<img th:src="@{/resources/static/images/logo.png}">
<img th:src="@{src/main/resources/static/images/logo.png}">
<img th:src="@{/src/main/resources/static/images/logo.png}">
<img src="/static/images/logo.png">
<img src="static/images/logo.png">
<img src="/resources/static/images/logo.png">
<img src="resources/static/images/logo.png">
<img src="/main/resources/static/images/logo.png">
<img src="main/resources/static/images/logo.png">
<img src="src/main/resources/static/images/logo.png">
<img src="/src/main/resources/static/images/logo.png">
<img src="hotelreservation/src/main/resources/static/images/logo.png">
<img src="/hotelreservation/src/main/resources/static/images/logo.png">
<img src="D:/Users/Maciek/Documents/git/hotelreservation/src/main/resources/static/images/logo.png">
<img src="D:\Users\Maciek\Documents\git\hotelreservation\src\main\resources\static\images\logo.png">
<footer th:replace="fragments/footer"></footer>
</body>
</html>
次のように削除し~
ます:
<img th:src="@{/images/logo.png}">
また、Spring Securityを使用している場合は、Security Configurationクラス(WebSecurityConfigurerAdapterを拡張するクラス)でこのメソッドをオーバーライドして、リソースへのリクエストを許可してください。
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("static/**");
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加