Spring Boot アプリケーションの静的フォルダーの下にファイルをロードする際に問題があります。
問題は RequestMapping の深さが 2 以上のようです@RequestMapping("spring/xyz")
単一の@RequestMapping("spring")
深さはうまく機能しますが、深さ 2 の接頭辞は「spring」で、接続は localhost:8080/spring/'static folder' です。
ここで半分の解決策を見つけました
私のフォルダ構造は次のとおりです。
static/css/some.css
static/templates/velocity.vm
ケース 1: うまく機能する
java:
@RequestMapping("spring")
html:
<link rel="stylesheet" href="css/some.css">
case2: うまくいく
java:
@RequestMapping("spring/xyz")
html:
<link rel="stylesheet" href="../css/some.css">
ケース 3: 動作しない
java:
@RequestMapping("spring/xyz/123")
html:
<link rel="stylesheet" href="../css/some.css">
いわゆる'http//localhost/spring/xyz/css/some.css'
case3: よく動く
java:
@RequestMapping("spring/xyz/123")
html:
<link rel="stylesheet" href="../../css/some.css">
case4: よく動く
java:
@RequestMapping("123")
html:
<link rel="stylesheet" href="../../css/some.css">
できます!!../../
相対パスを使用しても。なぜこれが機能するのかわかりません。
実際、Spring Boot API をよく理解していなかったので、ViewResoler を使用して他の静的リソースをロードすることを検討しました。
このロード パス メカニズムと、RequestMapping URL パス リンクから「http://localhost/spring/xyz/css/some.css」を呼び出す方法を知りたい
回答よろしくお願いします~!!
ここで「metalhead」と「Brian Clozel」からspring.io の同じ問題を参照します。