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

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2021-12-16
  • 2021-11-13
  • 2021-11-02
  • 2021-12-05
  • 2022-12-23
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
相关资源
相似解决方案