3 回答
TA贡献1811条经验 获得超4个赞
model.addAttribute 可以在您的 html 文件中获取数据。您方法中的 return 应该返回您想要的模板的名称。例如你的 hello.html
在你的 hello.html 中放置如下内容:
<p th:text="${name}"></p>
那么它应该工作。
您的控制器看起来像这样,因此返回包含来自 hello.html 的模板名称 hello:
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
model.addAttribute("name", name);
return "hello";
}
TA贡献1735条经验 获得超5个赞
您可能对控制器使用了不正确的注释。
用
@控制器
这是示例:
@Controller
public class MyController {
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
model.addAttribute("name", name);
return "hello";
}
}
TA贡献1865条经验 获得超7个赞
您必须更改依赖项,而不是org.thymeleaf
需要以下依赖项:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '1.5.1.RELEASE'
我希望这能解决您的问题。
添加回答
举报