Spring-通过链接传递参数 [英] Spring - pass parameters through link
问题描述
假设我在Spring Web应用程序视图中有一个对象列表.假设这些对象是论坛主题.他们每个人都有一个链接,该链接将转到包含该主题所有主题的页面.现在,为了列出这些主题,我将需要保留选择的线程ID. .jsp的一部分,包含链接:
Suppose I have a list of objects in a Spring web application view. Suppose these objects are forum threads. Each of them has a link, which will move to the page with all topics for this thread. Now in order to list those topics, I will need to retain the thread id which was selected. Part of the .jsp that contains the link:
<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>
现在,据我了解,我将需要通过请求映射来获取参数:
Now, from what I understand, I will need to take the param by request mapping:
@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();
}
}
我不能理解的是通过它.我如何在单击此链接时包括该请求将获得该参数的信息?
What I can't get right, is passing it. How can I include, that on clicking this link, the request will get that parameter?
推荐答案
将ID添加到链接:
<td><a href="topics.html?getId=${thread.id}">Open</a></td>
这篇关于Spring-通过链接传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!