使用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