使用thymeleaf,跳转到对应页面,但是没有在页面上显示对应的数据


@Controller
public class HelloWorldController {

    @RequestMapping("success")
    public String success(Map<String,Object> map) {
        map.put("hello","你好");
        return"success";
    }
}

 

模版为:

<!DOCTYPE html>
<!--为了语法提示   xmlns:th="http://www.thymeleaf.org"-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Success</title>
</head>
<body>
成功
<!--th:text 将div里面的内容设置为-->
<div th:text="${hello}">
    这里显示欢迎信息
</div>
</body>
</html>

在这里切记:不能使用@RestController这个注解。因为这个注解使用流的形式进行返回数据。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM