【发布时间】:2020-10-30 08:49:40
【问题描述】:
在我的 .java 文件中,我有
@RequestMapping(value = "/page1", method = RequestMethod.GET)
public String callback(@RequestParam(name = "token") String token, Model model){
//do something with token
//result variable is either
//"<p style=\"color:red;font-size:20px\"><strong>fail</strong></p>"
//or
//"<p style=\"color:green;font-size:20px\"><strong>pass</strong></p>"
model.addAttribute("result", result);
return "page1";
在我的 page1.html 文件中:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Page1</title>
</head>
<body>
<p th:text="'here is the result: ' + ${result}"></p>
</body>
</html>
现在,我的 page1 显示:
here is the result: <p style="color:green;font-size:20px"><strong>pass</strong></p>
是否可以将我的结果变量呈现为 html,以便我的 page1 显示一个大的绿色通道?除了 th:text + ${var} 还有其他格式选项吗?我使用的是 spring boot 和 thymeleaf。我试图不为此使用 javascript。
类似 this 的东西,但用于 java
【问题讨论】:
标签: java html spring-boot model-view-controller thymeleaf