- 我有 2 個 根本原因問題/錯誤
org.attoparser.ParseException: Error resolving template [components/folder-list], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "inbox-page" - line 65, col 14)org.thymeleaf.exceptions.TemplateInputException: Error resolving template [components/folder-list], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "inbox-page" - line 65, col 14)
- 當我轉換一些 .html 代碼并嘗試將其提取為組件時出現了該錯誤。
- 我嘗試了從絕對路徑到包路徑的不同路徑;無論如何,路徑都無法被識別。
模板/收件箱-page.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Inbox</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r 8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-U1DAWAznBHeqEIlVSCgzq c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj"
crossorigin="anonymous"
></script>
<style>
.container {
display: grid;
grid-template-areas:
"header header header"
"nav content content"
"footer footer footer";
grid-template-columns: 300px 1fr;
grid-template-rows: auto 1fr auto;
grid-gap: 10px;
height: 100vh;
}
header {
grid-area: header;
}
nav {
grid-area: nav;
margin-left: 0.5rem;
}
main {
grid-area: content;
}
footer {
grid-area: footer;
}
</style>
</head>
<body>
<div >
<header>
<h1>Welcome, Name</h1>
</header>
<nav>
<div th:insert="components/folder-list :: folder-list (panelName = 'Folders', folders = ${defaultFolders})" ></div>
<div th:insert="components/folder-list :: folder-list (panelName = 'My folders', folders = ${userFolders})"></div>
</nav>
<main>
<p> Email LIST</p>
</main>
<footer>
<!-- Footer content -->
</footer>
</div>
</body>
</html>
模板/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Demo</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width" />
<base href="/" />
</head>
<body>
<h1>Login</h1>
<div>
With GitHub: <a href="/oauth2/authorization/github">click here</a>
</div>
</body>
</html>
組件/檔案夾串列.html
<!DOCTYPE html>
<html >
<head>
</head>
<body>
<div th:fragment="folder-list (panelName, folders)">
<div th:if="${folders}">
<div th:text="${panelName}">Folders</div>
<div >
<div >
<li
th:each="folder :: ${folders}"
>
<span th:text="${folder.label}">Folder</span>
<span >15</span>
</li>
</div>
</div>
</body>
</html>
收件箱應用程式.java DriverCode
package io.aharo.inbox;
import io.aharo.inbox.folders.Folder;
import io.aharo.inbox.folders.FolderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.cassandra.CqlSessionBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import java.nio.file.Path;
@SpringBootApplication
@RestController
public class InboxApp
{
@Autowired
private FolderRepository folderRepository;
public static void main(String[] args) {
SpringApplication.run(InboxApp.class, args);
// System.out.println(folderRepository);
// FolderRepository fr = new FolderRepository("aharo", "idk", "red");
}
/**
* This is neccesary for the Spring Boot App to use the Astra secure bundle
* && connect to our database.
*/
@Bean
public CqlSessionBuilderCustomizer sessionBuilderCustomizer (DataStaxAstraProperties astraProperties)
{
Path bundle = astraProperties.getSecureConnectBundle().toPath();
return builder -> builder.withCloudSecureConnectBundle(bundle);
}
@PostConstruct
public void init()
{
folderRepository.save( new Folder("aharo","Inbox", "blue"));
folderRepository.save( new Folder("aharo","Sent", "green"));
folderRepository.save( new Folder("aharo","Important", "yellow "));
}
// @RequestMapping("/user")
// public String user(@AuthenticationPrincipal OAuth2User principal) {
// System.out.println(principal);
// return principal.getAttribute("name");
// }
}
環境樹
- 我無法顯示圖片,但我的專案作業樹環境看起來像這樣。
.
├── mvnw
├── mvnw.cmd
├── pom.xml
├── README.md
├── src
│ └── main
│ ├── java
│ │ └── io
│ │ └── aharo
│ │ └── inbox
│ │ ├── controllers
│ │ │ └── InboxController.java
│ │ ├── DataStaxAstraProperties.java
│ │ ├── folders
│ │ │ ├── Folder.java
│ │ │ ├── FolderRepository.java
│ │ │ └── FolderService.java
│ │ ├── InboxApp.java
│ │ └── SecurityAdapter.java
│ └── resources
│ ├── application.yml
│ ├── components
│ │ └── folder-list.html
│ ├── META-INF
│ │ └── additional-spring-configuration-metadata.json
│ ├── secure-connect.zip
│ └── templates
│ ├── inbox-page.html
│ └── index.html
└── target
├── classes
│ ├── application.yml
│ ├── components
│ │ └── folder-list.html
│ ├── io
│ │ └── aharo
│ │ └── inbox
│ │ ├── controllers
│ │ │ └── InboxController.class
│ │ ├── DataStaxAstraProperties.class
│ │ ├── folders
│ │ │ ├── Folder.class
│ │ │ ├── FolderRepository.class
│ │ │ └── FolderService.class
│ │ ├── InboxApp.class
│ │ └── SecurityAdapter.class
│ ├── META-INF
│ │ └── additional-spring-configuration-metadata.json
│ ├── secure-connect.zip
│ └── templates
│ ├── inbox-page.html
│ └── index.html
├── generated-sources
│ └── annotations
├── maven-status
│ └── maven-compiler-plugin
│ └── compile
│ └── default-compile
舊代碼
- 模板/收件箱-page.html
old但有效。 - 如果我們用這個舊代碼交換新的 inbox-page.html,它會作業,但我想要將它轉換為一個組件。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Inbox</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r 8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-U1DAWAznBHeqEIlVSCgzq c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj"
crossorigin="anonymous"
></script>
<style>
.container {
display: grid;
grid-template-areas:
"header header header"
"nav content content"
"footer footer footer";
grid-template-columns: 300px 1fr;
grid-template-rows: auto 1fr auto;
grid-gap: 10px;
height: 100vh;
}
header {
grid-area: header;
}
nav {
grid-area: nav;
margin-left: 0.5rem;
}
main {
grid-area: content;
}
footer {
grid-area: footer;
}
</style>
</head>
<body>
<div >
<header>
<h1>Welcome, Name</h1>
</header>
<nav>
<div >
<div >defaultFolders</div>
<div >
<ul >
<li
th:each="folder : ${defaultFolders}"
>
TMP
<span th:text="${folder.label}"> Label</span>
<span >69</span>
</li>
</ul>
</div>
<div
th:if="${userFolders}">
<div >userFolders</div>
<div >
<ul >
<li
th:each="folder : ${defaultFolders}"
>
TMP
<span th:text="${folder.label}"> Label</span>
<span >24</span>
</li>
</ul>
</div>
</nav>
<main>
<div >
<div >Inbox</div>
<div >
<div >
<a
href="#"
aria-current="true"
>
<div >
<h5 >LIST GROUP</h5>
<small></small>
</div>
<p ></p>
<small></small>
</a>
<a href="#" >
<div >
<h5 >LIST GROUP</h5>
<small ></small>
</div>
<p ></p>
<small ></small>
</a>
<a href="#" >
<div >
<h5 >LIST GROUP</h5>
<small ></small>
</div>
<p ></p>
<small ></small>
</a>
</div>
</div>
</div>
</main>
<footer>
<!-- Footer content -->
</footer>
</div>
</body>
</html>
uj5u.com熱心網友回復:
將components檔案夾移動到templates. Thymeleaf 搜索所有與templates.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/529534.html
