1.ディレクトリ構造
1.src / main / java:Javaコードを保存する
2. src / main / resources
- リソース:(Spring Bootのデフォルト)リソースファイルを保存する
- static:(Spring Boot default)css、js、imageなどの静的ファイルを保存する(http:// localhost:8080 / js / main.jsにアクセス)
- public:(Spring Bootのデフォルト)パブリックファイルを格納します
- テンプレート:(ユーザー定義、任意の名前を付けることができますが、ここでは認識されたファイル名が使用されます)jsp、htmlなどの静的ページを保存します
- config:(ユーザー定義、好きな名前を付けることができますが、ここでは認識されたファイル名を使用します)application.propertiesなどの構成ファイルを保存します
2.同じファイル、静的リソースファイルの読み込みシーケンス
META/resources > resources > static > public
直接戻る場合は、適切なリソースが存在するかどうかを見つけるために、デフォルトから1つずつSpring Bootを実行します。
例:これらのフォルダーに新しいjsファイルを作成して、どのファイルがロードされるかを確認してみましょう。
アドレスバーに次のアドレスを入力します。http:// localhost:8080 / test.js。ここでは、resourcesフォルダーの下にtest.jsファイルを作成しなかったため、静的フォルダーの下にファイルをロードします
3、テンプレートフォルダー
テンプレートフォルダー内のファイルは、アクセスできるように転送する必要があります
テンプレートはSpring Bootのデフォルトフォルダーではないため、このフォルダー内のファイルにアクセスできません
1.アクセスするには、依存関係を導入する必要があります
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.コントローラを書く
@Controller
public class jumpController {
@RequestMapping("/index")
public String index() {
return "index";
}
}
3. thymeleaf構成ファイル(application.propertiesで構成)
#####Thymeleaf配置文件
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML
#编码
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.check-template=true
#类型
spring.thymeleaf.servlet.content-type=text/html
#前缀
spring.thymeleaf.prefix=classpath:/templates/
#后缀
spring.thymeleaf.suffix=.html
現時点localhost:8080/index
では、テンプレートの下でindex.htmlにアクセスできます
4、読み込み順序を自分で定義するか、独自の新しいフォルダを追加します
application.propertiesを編集します
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
公式ウェブサイトの説明:
https : //docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content