Thymeleaf th:text returns null



im尝试使用Model对象进行简单的数据绑定,并使用Thymelaf在html页面上显示值。th:text中的字符串文字显示良好,但当我尝试显示属性的值时,我会得到null。

提前谢谢。

package control;
import java.time.LocalDate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class Controls {
@GetMapping("/")
public String index(Model model) {
// Pass the date to the view
model.addAttribute("serverDate", LocalDate.now());
return "index";
}
}

<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">
<head>
<title>Index Page</title>
</head>
<body>
<h1>Showing Date</h1>
<h1 style="color:green;" th:text="'Today is ' + ${serverDate}">Today is Someday.</h1>
</body>
</html>

对不起,伙计们,我只是把control.java放错了包,这就是它没有正确绑定的原因。

最新更新