我正在使用Struts2,并希望使用Struts2检查HashSet属性大小是否大于零。
struts.xml中
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
POJO
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="bundle" extends="struts-default" namespace="/">
<action name="process"
class="sample.action.Process"
method="execute">
<interceptor-ref name="defaultStack" />
<result name="success">/jsp/result.jsp</result>
</action>
</package>
</struts>
行动类
package sample.pojo;
public class Customer{
private Integer id;
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
查看
package sample.action;
import java.util.HashSet;
import java.util.Set;
import sample.pojo.Customer;
import com.opensymphony.xwork2.ActionSupport;
public class Process extends ActionSupport
{
private Set<Customer> result = new HashSet<Customer>();
public String execute()
{
Customer cust1 = new Customer();
cust1.setId(1);
cust1.setAge(59);
cust1.setName("Subramanian");
result.add(cust1);
return SUCCESS;
}
public Set<Customer> getResult() {
return result;
}
public void setResult(Set<Customer> result) {
this.result = result;
}
}
如果要在View中使用标记语法,请帮助Struts2。谢谢!
答案 0 :(得分:0)
以下代码段为我工作
<s:if test="%{mySet.size()>0}">