A ton of questions have been asked about connecting Thymeleaf + CSS and Spring Boot. I could not find any that addressed this problem with Ktor.
I have this template:
<!DOCTYPE html>
<html xmlns:th="; lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" th:href="@{/assets/css/style.css}">
</head>
<body>
...
</body>
</html>
This is what the file structure looks like:
src/main/resources/assets/css/style.css
src/main/resources/templates/thymeleaf/books.html
The templating plugin is set up in the following way:
fun Application.configureTemplating() {
install(Thymeleaf) {
setTemplateResolver(ClassLoaderTemplateResolver().apply {
prefix = "templates/thymeleaf/"
suffix = ".html"
characterEncoding = "utf-8"
})
}
}
This setup works fine without linking CSS, but when trying to link CSS, this error occurs:
.thymeleaf.exceptions.TemplateProcessingException: Link base "/assets/css/style.css" cannot be context relative (/...) unless the context used for executing the engine implements the .thymeleaf.context.IWebContext interface (template: "books" - line 5, col 26)
Please help me solve this problem. Thanks in advance
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745648671a4638125.html
评论列表(0条)