Spring - 通过 link 传递参数
Spring - pass parameters through link
假设我在 Spring Web 应用程序视图中有一个对象列表。假设这些对象是论坛线程。他们每个人都有一个 link,它将移动到包含该线程所有主题的页面。现在为了列出这些主题,我需要保留所选的线程 ID。包含 link:
的 .jsp 的一部分
<h3><spring:message code="label.threadList"/></h3>
<c:if test="${!empty threadList}">
<table class="data">
<tr>
<th><spring:message code="label.threadName"/></th>
<th><spring:message code="label.threadDescription"/></th>
<th><spring:message code="label.threadTopicCount"/></th>
<th><spring:message code="label.threadLastModified"/></th>
<th>Go</th>
</tr>
<c:forEach items="${threadList}" var="thread">
<tr>
<td>${thread.name} </td>
<td>${thread.description} </td>
<td>${thread.topics}</td>
<td>${thread.last_modified}</td>
<td><a href="topics.html">Open</a></td>
</tr>
</c:forEach>
</table>
现在,据我了解,我需要通过请求映射获取参数:
@Controller
public class TopicPageController {
@RequestMapping(value = "/topics", method = RequestMethod.GET)
public ModelAndView helloWorld(@RequestParam("getId") int getId) {
System.out.println(getId); //here's when I want to see the param
return new ModelAndView();
}
}
我不能做对的是通过它。我如何添加,在单击此 link 时,请求将获得该参数?
将 id 添加到 link:
<td><a href="topics.html?getId=${thread.id}">Open</a></td>
假设我在 Spring Web 应用程序视图中有一个对象列表。假设这些对象是论坛线程。他们每个人都有一个 link,它将移动到包含该线程所有主题的页面。现在为了列出这些主题,我需要保留所选的线程 ID。包含 link:
的 .jsp 的一部分<h3><spring:message code="label.threadList"/></h3>
<c:if test="${!empty threadList}">
<table class="data">
<tr>
<th><spring:message code="label.threadName"/></th>
<th><spring:message code="label.threadDescription"/></th>
<th><spring:message code="label.threadTopicCount"/></th>
<th><spring:message code="label.threadLastModified"/></th>
<th>Go</th>
</tr>
<c:forEach items="${threadList}" var="thread">
<tr>
<td>${thread.name} </td>
<td>${thread.description} </td>
<td>${thread.topics}</td>
<td>${thread.last_modified}</td>
<td><a href="topics.html">Open</a></td>
</tr>
</c:forEach>
</table>
现在,据我了解,我需要通过请求映射获取参数:
@Controller
public class TopicPageController {
@RequestMapping(value = "/topics", method = RequestMethod.GET)
public ModelAndView helloWorld(@RequestParam("getId") int getId) {
System.out.println(getId); //here's when I want to see the param
return new ModelAndView();
}
}
我不能做对的是通过它。我如何添加,在单击此 link 时,请求将获得该参数?
将 id 添加到 link:
<td><a href="topics.html?getId=${thread.id}">Open</a></td>