1

弹簧形式如下:

<form:form method="post" action="list.html">

    <table>
    <tr>
        <td><form:label path="entity"><spring:message code="label.entity"/></form:label></td>
        <td><form:input path="entity" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="<spring:message code="label.listmessage"/>"/>
        </td>
    </tr>
</table> 
</form:form>


<h3>Messages</h3>
<c:if  test="${!empty messageList}">
<table class="data">
<tr>
    <th>Entity</th>
    <th>Available</th>
    <th>&nbsp;</th>
</tr>
<c:forEach items="${messageList}" var="message">
    <tr>
        <td>${message.entity}</td>
        <td>${message.available}</td>
     </tr>
</c:forEach>
</table>
</c:if>

我需要帮助编写将捕获表单帖子的控制器代码;并返回要显示的消息列表:

@RequestMapping(value = "/list", method = RequestMethod.POST)
public String listMessages(String prefixId,Map<String, Object> map) {
    map.put("list",messageService.getMessagesByEntity(prefixId));
    return "redirect:/list";
}

上述方法不起作用 - 但我需要帮助才能获得正确的适应。
任何帮助表示赞赏

4

1 回答 1

0

这个

<input type="submit" value="<spring:message code="label.listmessage"/>"/>

不会做任何事情。POST 表单甚至不会包含它,因为它没有名称。从...开始

<input name="listMessage" type="submit" value="<spring:message code="label.listmessage"/>"/>

当浏览器发送请求时,它会添加一个参数,如listMessage=[whatever value is in label.listmessage]. 您可以将此请求参数检索为

@RequestMapping(value = "/list", method = RequestMethod.POST)
public String listMessages(@RequestParam(value="listMessage") String listMessage, Model model) {
    // get whatever you need with the request param and put it in the model
    model.addAttribute("messageList",messageService.getMessagesByEntity(listMessage));
    return "redirect:/list";
}

模型中的属性被添加到请求属性中,因此在带有${messageList}.

于 2013-08-29T17:09:37.823 回答