#spring-boot #kotlin #thymeleaf
Вопрос:
Я заявляю все, что касается требования, но я не знаю, где я ошибаюсь. Выражения Тимелифа не выглядят должным образом. объявил все правильно, пока я запускаю свою программу и звоню на локальный хост:8080 в браузере, я получаю ниже thpe ошибки
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "page.content" (template: "page" - line 14, col 28)
at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:292) ~[thymeleaf-spring5-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariableExpression(VariableExpression.java:166) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:66) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:109) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
at org.thymeleaf.standard.expression.Expression.execute(Expression.java:138) ~[thymeleaf-3.0.12.RELEASE.jar:3.0.12.RELEASE]
page.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments/head">
</head>
<body>
<nav th:replace="/fragments/nav :: nav-front"></nav>
<div class="container-fluid mt-5">
<div class="row">
<div th:replace="/fragments/categories"></div>
<div class="col"></div>
<div class="col-7" th:utext="${page.content}"></div>
<div class="col"></div>
</div>
</div>
<div th:replace="/fragments/footer"></div>
</body>
</html>
Контролер страниц.кт
package com.nilmani.cmsshopingcart.controller
import com.nilmani.cmsshopingcart.model.Page
import com.nilmani.cmsshopingcart.repository.PageRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
@Controller
@RequestMapping("/")
class PageController {
@Autowired
private lateinit var pageRepo: PageRepository
@GetMapping
fun home(model: Model): String {
val page: Page? = pageRepo.findBySlug("home")
model.addAttribute("page", page)
return "page"
}
@GetMapping("/login")
fun login(): String? {
return "login"
}
@GetMapping("/{slug}")
fun page(@PathVariable slug: String, model: Model): String? {
val page: Page = pageRepo.findBySlug(slug) ?: return "redirect:/"
model.addAttribute("page", page)
return "page"
}
}
page.kt
package com.nilmani.cmsshopingcart.model
import javax.persistence.*
@Entity
@Table(name = "pages")
data class Page(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id:Int=0,
val title:String="",
@Column(nullable = false)
var slug:String="",
val content:String="",
var sorting:Int=0
)
Я объявил все, что использовал в своем проекте, но не знаю, почему
возникают такие типы ошибок