Spring - pass parameters through link

☆樱花仙子☆ 提交于 2019-12-10 09:48:36

问题


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?


回答1:


Add the id to the link:

 <td><a href="topics.html?getId=${thread.id}">Open</a></td>


来源:https://stackoverflow.com/questions/28333860/spring-pass-parameters-through-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!