添加到模型后,百里香叶页面上的字符串为空



我的控制器:

@Controller
public class IndexController {
@RequestMapping(value = "/index")
public String index(Model model) {
model.addAttribute("message", "Hello World!");
return "index";
}
}

我的页面:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset = "ISO-8859-1" />
<link href = "css/styles.css" rel = "stylesheet"/>
<title>Spring Boot Application</title>
</head>
<body>
<h4>Spring boot.</h4>
<p th:utext="${message}"></p>
</body>
</html>

加载和呈现后,将显示此 HTML;如何显示消息?

<!DOCTYPE html>
<html>
<head>
<meta charset = "ISO-8859-1" />
<link href = "css/styles.css" rel = "stylesheet"/>
<title>Spring Boot Application</title>
</head>
<body>
<h4>Spring boot.</h4>
<p></p>
</body>
</html>

确保已将百里叶依赖项导入到项目中。 使用th:text="${message}"

IndexController 中的方法永远不会被调用,因为:

@RequestMapping(value = "/index")

应该是这样的:

@RequestMapping(value = "/")

最新更新