gpt4 book ai didi

java - 使用 DisplayTag 库框架通过 Struts2 进行分页

转载 作者:行者123 更新时间:2023-11-30 05:16:45 25 4
gpt4 key购买 nike

我想为我的应用程序的某些类应用分页,其中我使用 spring、struts2 和 hibernate。这里我从welcome.jsp 文件中调用action 类。它有以下代码:

<s:form action="marketing/allCountry.action">  
<s:submit value="Click"></s:submit>
</s:form>

现在我的 java 的 allCountry.action 类具有以下代码:

public String executeAction() throws Exception {
try {
countryList = new ArrayList<Country>();
countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
System.out.println("countryList = "+countryList);
return ActionSupport.SUCCESS;

} catch (Exception ex) {
return ActionSupport.ERROR;
}
}

它正确获取数据,我通过打印countryList对象确认了这一点。但现在我从 SUCCESS 重定向到 country.jspcountry.jsp的代码是:

<display:table list="countryList" requestURI="CountryAllAction" pagesize="3">
<display:column property="id" title="ID" />
<display:column property="name" />
</display:table>

现在,在执行我的应用程序时,我收到如下运行时错误:

javax.servlet.ServletException: javax.servlet.ServletException: Exception: [.LookupUtil] Error looking up property "id" in object type "java.lang.String". Cause: Unknown property 'id'

解决此类错误的方法是什么?

最佳答案

您需要在操作中为您的国家/地区列表提供 getter。

List<Country> countryList = new ArrayList<Country>();

public String executeAction() throws Exception {
try {
countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
System.out.println("countryList = "+countryList);
return ActionSupport.SUCCESS;

} catch (Exception ex) {
return ActionSupport.ERROR;
}

}

public List<Country> getCountryList() {
return countryList;
}

关于java - 使用 DisplayTag 库框架通过 Struts2 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/777199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com