Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 百里香不';t绑定弹簧&x27;s模型和视图_Spring_Spring Mvc_Thymeleaf - Fatal编程技术网

Spring 百里香不';t绑定弹簧&x27;s模型和视图

Spring 百里香不';t绑定弹簧&x27;s模型和视图,spring,spring-mvc,thymeleaf,Spring,Spring Mvc,Thymeleaf,我有一个这样的控制器: @Controller public class HelloController { @Autowired private SomeService someService; @RequestMapping("/") public ModelAndView index() { ModelAndView mav = new ModelAndView("index"); mav.addObject("title", someService.getTitle(

我有一个这样的控制器:

@Controller
public class HelloController {

@Autowired
private SomeService someService;

@RequestMapping("/")
public ModelAndView index() {
    ModelAndView mav = new ModelAndView("index");
    mav.addObject("title", someService.getTitle());
    mav.addObject("text", someService.getText());
    return mav;
}
}

现在,thymeleaf应该对mav有一些了解:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="de">

    <title>${title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
    <h1>${title}</h1>
    <h2>${text}</h2>
</body>
</html>
有什么想法吗?我是否缺少有关Spring中ViewResolver的某些配置?

已修复:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="de">

    <title th:text="${title}"></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
    <h1 th:text="${title}"></h1>
    <h2 th:text="${text}">My Dummy Data</h2>
</body>
</html>

我的虚拟数据

我意识到这是一个4年前的问题,Stefano的答案是正确的。但这也是正确的(内联):


${title}
[${title}]]
[${text}]]
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="de">

    <title th:text="${title}"></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
    <h1 th:text="${title}"></h1>
    <h2 th:text="${text}">My Dummy Data</h2>
</body>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="de">

    <title>${title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
    <h1>[[${title}]]</h1>
    <h2>[[${text}]]</h2>
</body>
</html>