我想从胸腺叶页面访问其他服务器的url。该怎么做呢?看看我的控制器。
@GetMapping("/getJSPage")
public String getJSP(Model theModel)
{
// String url = "https://test-node-api-test.herokuapp.com/";
Email email = new Email();
theModel.addAttribute("email", email);
return "test";
}
我的电子邮件类
class Email
{
private String mail;
public String getURL(){
return "https://test-node-api-test.herokuapp.com/";
}
}
这是我的test.HTML文件
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Send HTML Email using JSP</title>
</head>
<body>
<h1>Send Email using JSP</h1>
<p>
<a th:href="@{email.getUrl()}"> clickable</a>
<a th:href="@{https://test-node-api-test.herokuapp.com/}"> clickable</a>
</p>
</body>
</html>
下面的链接<a th:href="@{https://test-node-api-test.herokuapp.com/}"> clickable</a>
是硬编码,它正在工作,但<a th:href="@{email.getUrl()}"> clickable</a>
生成错误
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "@{email.getUrl()}" (template: "test" - line 10, col 8)
我该如何解决这个问题呢?
发布于 2020-05-01 21:22:33
根据Standard URL Syntax,如果您想在创建url时使用表达式,则必须用${...}
将其括起来。
<a th:href="@{${email.getURL()}}"> clickable</a>
此外,getURL()
应该与getter完全匹配。您的示例代码中包含getURL()
和getUrl()
。
https://stackoverflow.com/questions/61541985
复制相似问题