@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這個注解。因為這個注解使用流的形式進行返回數據。