我试图实现this教程,但我不明白message/list
是什么意思.我创建了一个Spring Boot应用程序,它使用另一个API,以JSON格式获取数据,并将其存储在PostgreSQL数据库中.
我数据库中的一列是来自该API的URL.我使用Thymeleaf在HTML的前端显示它们.我的目标是创建一个URL前端,当用户单击它们时,将它们重定向到我的应用程序之外的适当网站.
我必须同时将从Thymeleaf到控制器的数据传输和从控制器到应用程序外部的重定向结合起来.
有没有可能这样做?下面我向你们展示了我的前端代码,下面是我试图实现的控制器,但没有成功,因为它给了我.
java.lang.IllegalArgumentException: Model has no value for key 'rate.news_link'
FrontEnd
<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:c="http://www.w3.org/1999/XSL/Transform"
xmlns:https="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Spring Boot Thymeleaf Hello World Example</title>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/styles/db.css}"/>
<script type="text/javascript" th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
</head>
<body>
<ul>
<li><a href="http://localhost:8080/">Home</a></li>
<li><a href="https://github.com/Andreas-Kreouzos" target="_blank">Github</a></li>
</ul>
<main role="main" class="container">
<div class="starter-template">
<h1>Cryptocurrency News</h1>
</div>
</main>
<!--Display DB contents on HTML and Thymeleaf-->
<div class="container text-center" id="tasksDiv">
<hr>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>News Provider Name</th>
<th>News Link</th>
<th>Related Image</th>
</tr>
</thead>
<tbody>
<tr th:each="rate: ${rates}">
<td th:text="${rate.news_provider_name}"> </td>
<td>
<a
href="#"
th:href="${rate.news_link}"
th:text="${rate.HEADLINE}">
</a>
</td>
<td> <img th:src="${rate.related_image}" alt="error displaying image"> </td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
Controller
@RequestMapping("/")
public String redirect() {
return "redirect:/${rate.news_link}";
}