简体   繁体   English

Spring - 通过链接传递参数

[英]Spring - pass parameters through link

Suppose I have a list of objects in a Spring web application view. 假设我在Spring Web应用程序视图中有一个对象列表。 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. 现在,为了列出这些主题,我需要保留所选的线程ID。 Part of the .jsp that contains the 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>

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM