【发布时间】:2023-04-01 01:24:01
【问题描述】:
我在 Scala 中使用 Thymeleaf 和 Springboot。 当我从 HTML 页面发出 get 请求时,它会转到控制器并将下一个 HTML 文件名作为字符串而不是整个 HTML 返回。
我的 build.gradle
compile("org.thymeleaf:thymeleaf-spring4")
compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
我已经把所有的html放到了src/main/resources/templates
主 html
<html xmlns:th="http://www.thymeleaf.org">
<a href="#" th:href="@{/api/v1/users/userval}">Login</a>
控制器
@RestController
@RequestMapping(value = Array("/api/v1/users"),produces = Array("text/html"))
class UserController {
@RequestMapping(method = Array(RequestMethod.POST))
@ResponseStatus(value = HttpStatus.CREATED)
def createUser(@Valid @RequestBody user:User) = {
UserRepository.populateUser(user)
}
@RequestMapping(value=Array("/userval"),method = Array(RequestMethod.GET))
def userLoginForm( model:Model) = {
model.addAttribute("userLogin", new UserLogin())
"login"}
@RequestMapping(value=Array("/userval"),method = Array(RequestMethod.POST))
def getUser(@ModelAttribute userLogin:UserLogin, bindingResult: BindingResult) = {
"reservations"
}
在这里,当我单击主 HTML 中的登录链接时,我得到“登录”作为字符串而不是 login.html
【问题讨论】:
标签: scala spring-boot thymeleaf