@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这个注解。因为这个注解使用流的形式进行返回数据。
