デフォルトでは、Thymeleafはすべてのhtmlファイルがscr/main/java/resources/templatesに存在する必要があります。テンプレートフォルダに混乱を生じさせないために、そこに別のサブリーダーを作成する必要があります。問題はそこに置かれたhtmlファイルが決して解決されないということです。例は次のとおりです。Thymeleaf + Spring Boot:サブフォルダにhtmlを配置
構造:
IndexController:
@Controller
public class IndexController {
@GetMapping(value = "/")
public String index() {
return "index";
}
}
デフォルトテンプレート:
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<title>Default template</title>
</head>
<body>
<section id="site-content" layout:fragment="content"></section>
</body>
</html>
インデックス:
サブフォルダ内ページ:私はインデックスページを開き、page.htmlへのリンクをクリックすると
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default">
<head>
<meta charset="UTF-8">
<title>Page</title>
</head>
<body>
<div layout:fragment="content">
This is a page in the subfolder
</div>
</body>
</html>
、私はこれを取得:私が間違っていた何
?
おかげで、「リターン「サブフォルダを/ページ "'は助けました。私はjspに慣れてきました。返信用のフォルダ名を指定する必要はありません。単に名前を表示するだけです。 Thymeleafは少し違った話です。 – sva605