主题:遍历list
求助!
1.在javabean中定义相应的bean ,例如college其中包含属性如collegeid collegename
package com.yourcompany;
public class College implements java.io.Serializable {
private Integer collegeid;
private String collegename;
public College() {
}
public College(String collegename) {
this.collegename = collegename;
}
public Integer getCollegeid() {
return this.collegeid;
}
public void setCollegeid(Integer collegeid) {
this.collegeid = collegeid;
}
public String getCollegename() {
return this.collegename;
}
public void setCollegename(String collegename) {
this.collegename = collegename;
}
2.在action中通过sql语句找到相应的bean
3.建立list ,但要求list的类 如: List<com.yourcompany.Colleg> list名字
4.将通过sql找到的bean 转换为College类以后,再加入list
CollegeDAO collegedao=new CollegeDAO();
String strsql1="from College";
List findcollege=collegedao.getSession().createQuery(strsql1).list();
List<com.yourcompany.College> collegelp=new ArrayList();
College college=(College)findcollege.get(i);
collegelp.add(college);
request.setAttribute("collegelp", collegelp);
在jsp文件中
<logic:iterate name="collegelp" id="collegelp" type="College">
<option value="<bean:write name="collegelp" property="collegename"/>" >
<bean:write name="collegelp" property="collegename" />
</option></logic:iterate>'
但结果总是提示找不到相应的property.
1.在javabean中定义相应的bean ,例如college其中包含属性如collegeid collegename
package com.yourcompany;
public class College implements java.io.Serializable {
private Integer collegeid;
private String collegename;
public College() {
}
public College(String collegename) {
this.collegename = collegename;
}
public Integer getCollegeid() {
return this.collegeid;
}
public void setCollegeid(Integer collegeid) {
this.collegeid = collegeid;
}
public String getCollegename() {
return this.collegename;
}
public void setCollegename(String collegename) {
this.collegename = collegename;
}
2.在action中通过sql语句找到相应的bean
3.建立list ,但要求list的类 如: List<com.yourcompany.Colleg> list名字
4.将通过sql找到的bean 转换为College类以后,再加入list
CollegeDAO collegedao=new CollegeDAO();
String strsql1="from College";
List findcollege=collegedao.getSession().createQuery(strsql1).list();
List<com.yourcompany.College> collegelp=new ArrayList();
College college=(College)findcollege.get(i);
collegelp.add(college);
request.setAttribute("collegelp", collegelp);
在jsp文件中
<logic:iterate name="collegelp" id="collegelp" type="College">
<option value="<bean:write name="collegelp" property="collegename"/>" >
<bean:write name="collegelp" property="collegename" />
</option></logic:iterate>'
但结果总是提示找不到相应的property.