我正在使用 stripesframework 开发一个 Web 应用程序,但遇到了问题。我找到了解决方法,但我想知道为什么会发生这种情况。
我写了一个类
@UrlBinding("/subject/{subject_type}/{subject_name}")
public class SubjectActionBean extends ActionBean {
private String subjectType;
private String subjectName;
@Validate(required = true)
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
}
@Validate(required = true)
public void setSubjectType(String subjectType) {
this.subjectType = subjectType;
}
@DefaultHandler
public Resolution view() {
return new Resolution();
}
}
其中 subject_type 和 subject_name 根据调用操作的主题页面而变化。因此,调用将是 localhost/subject/applied/math。
到目前为止,一切都运行良好。当我尝试创建删除方法时出现问题
@HandlesEvent("remove")
public void removeSubject() {
}
并使用 localhost/subject/applied/math/remove 调用它 此时,stripes 开始提示没有调用的处理程序,也没有默认的处理程序。
因此,我删除了路径中的“{subject_type}/{subject_name}”并将它们作为参数传递,并在方法内部使用以下方法解压它们:
getContext().getRequest().getParameter();
这使得删除方法被调用。
我现在的问题是,为什么“{subject_type}/{subject_name}”使 stripes 无法找到删除方法。
最佳答案
尝试将@UrlBinding
更改为以下内容:
@UrlBinding("/subject/{subject_type}/{subject_name}/{$event}")
如果没有 {$event}
,Stripes 无法判断 URL 参数的哪一部分应该是事件。
此外,要进行测试,您可以尝试(使用当前的@UrlBinding
)访问localhost/subject/applied/math?remove=
希望有帮助。
关于stripes 不会调用所需的事件处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9595389/