【问题标题】:Spring @ActionMapping syntax for PortletsPortlet 的 Spring @ActionMapping 语法
【发布时间】:2012-12-20 01:20:40
【问题描述】:

我知道这在 url 包含参数“deleteItem=6”的情况下有效

@ActionMapping(params="deleteItem")
public void deleteItem(@ModelAttribute("items") Items items, BindingResult bindingResult, @RequestParam int deleteItem) throws Exception {
    items.getItems().remove(deleteItem);
    ...
}

但是我可以这样做吗(使用 deleteItem 参数的

@ActionMapping(params="deleteItem={idx}")
public void deleteItem(@ModelAttribute("items") Items items, BindingResult bindingResult, @RequestParam int idx) throws Exception {
    items.getItems().remove(idx);
    ...
}

没什么大不了的,就是代码更具可读性,因为它表明参数值是一个索引。

谢谢。

【问题讨论】:

    标签: spring model-view-controller portlet


    【解决方案1】:

    不,您不能像 @ActionMapping(params="deleteItem={idx}") 这样使用动态参数作为绑定名称,因为 Spring Portlet MVC 需要将方法绑定到具有唯一名称的操作。

    你的第一个 sn-p 是正确的。

    【讨论】:

    • 哦,好吧。如果它可以绑定到@ActionMapping(params="deleteItem") 这意味着'如果存在名为deleteItem 的参数时绑定',你会认为它可以多走一步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多