怎么样通过Struts+Hibernate显示主从表数据?
//主表beanpublic abstract class AbstractExamName implements java.io.Serializable {
// Fields
private String pk;
private String year;
private String term;
private String name;
private Set numberShowingsPlans = new HashSet(0);
// Constructors
/** default constructor */
public AbstractExamName() {
}
/** full constructor */
public AbstractExamName(String year, String term, String name, Set numberShowingsPlans) {
this.year = year;
this.term = term;
this.name = name;
this.numberShowingsPlans = numberShowingsPlans;
}
// Property accessors
public String getPk() {
return this.pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getYear() {
return this.year;
}
public void setYear(String year) {
this.year = year;
}
public String getTerm() {
return this.term;
}
public void setTerm(String term) {
this.term = term;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Set getNumberShowingsPlans() {
return this.numberShowingsPlans;
}
public void setNumberShowingsPlans(Set numberShowingsPlans) {
this.numberShowingsPlans = numberShowingsPlans;
}
public class ExamName extends AbstractExamName implements java.io.Serializable {
// Constructors
/**
*
*/
private static final long serialVersionUID = 1L;
/** default constructor */
public ExamName() {
}
/** full constructor */
public ExamName(String year, String term, String name, Set numberShowingsPlans) {
super(year, term, name, numberShowingsPlans);
}
}
//从表bean
public abstract class AbstractNumberShowingsPlan implements java.io.Serializable {
// Fields
private String pk;
private ExamName examName;
private String numberShowings;
private Date beginTime;
private Date endTime;
// Constructors
/** default constructor */
public AbstractNumberShowingsPlan() {
}
/** minimal constructor */
public AbstractNumberShowingsPlan(ExamName examName) {
this.examName = examName;
}
/** full constructor */
public AbstractNumberShowingsPlan(ExamName examName, String numberShowings, Date beginTime, Date endTime) {
this.examName = examName;
this.numberShowings = numberShowings;
this.beginTime = beginTime;
this.endTime = endTime;
}
// Property accessors
public String getPk() {
return this.pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public ExamName getExamName() {
return this.examName;
}
public void setExamName(ExamName examName) {
this.examName = examName;
}
public String getNumberShowings() {
return this.numberShowings;
}
public void setNumberShowings(String numberShowings) {
this.numberShowings = numberShowings;
}
public Date getBeginTime() {
return this.beginTime;
}
public void setBeginTime(Date beginTime) {
this.beginTime = beginTime;
}
public Date getEndTime() {
return this.endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public class NumberShowingsPlan extends AbstractNumberShowingsPlan implements java.io.Serializable {
// Constructors
/**
*
*/
private static final long serialVersionUID = 1L;
/** default constructor */
public NumberShowingsPlan() {
}
/** minimal constructor */
public NumberShowingsPlan(ExamName examName) {
super(examName);
}
/** full constructor */
public NumberShowingsPlan(ExamName examName, String numberShowings, Date beginTime, Date endTime) {
super(examName, numberShowings, beginTime, endTime);
}
}
--------------------------------hibernate配置-------------------------------------------------------
<hibernate-mapping>
<class name="com.ems.database.hibernate3.pojo.ExamName" table="EXAM_NAME" schema="EMS">
<id name="pk" type="string">
<column name="PK" length="32" />
<generator class="uuid.hex" />
</id>
<property name="year" type="string">
<column name="YEAR" length="10" />
</property>
<property name="term" type="string">
<column name="TERM" length="10" />
</property>
<property name="name" type="string">
<column name="NAME" length="50" />
</property>
<set name="numberShowingsPlans" inverse="true" lazy="false">
<key>
<column name="FK_EXAM_NAME" length="32" not-null="true" />
</key>
<one-to-many class="com.ems.database.hibernate3.pojo.NumberShowingsPlan" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.ems.database.hibernate3.pojo.NumberShowingsPlan" table="NUMBER_SHOWINGS_PLAN" schema="EMS">
<id name="pk" type="string">
<column name="PK" length="32" />
<generator class="uuid.hex" />
</id>
<many-to-one name="examName" class="com.ems.database.hibernate3.pojo.ExamName" fetch="select">
<column name="FK_EXAM_NAME" length="32" not-null="true" />
</many-to-one>
<property name="numberShowings" type="string">
<column name="NUMBER_SHOWINGS" length="20" />
</property>
<property name="beginTime" type="date">
<column name="BEGIN_TIME" length="7" />
</property>
<property name="endTime" type="date">
<column name="END_TIME" length="7" />
</property>
</class>
</hibernate-mapping>
-------------------------------------------------Struts jsp页面显示-----------------------------------------
<logic:present name="QueryObject">
<TABLE border="0" cellspacing="1" cellpadding="2" width="100%" align="center" class="tableborder">
<TR class="trHead">
<TD width="8%" height="23" align="center">
<bean:message key="com.sel"/>
</TD>
<TD width="12%" align="center">
<bean:message key="com.year"/>
</TD>
<TD width="20%" align="center">
<bean:message key="examname.term"/>
</TD>
<TD width="50%" align="center">
<bean:message key="examname.name"/>
</TD>
<TD width="10%" align="center">
<bean:message key="com.oper"/>
</TD>
</TR>
<logic:iterate id="element" name="QueryObject">
<TR class="tr">
<TD width="8%" height="20" align="center">
<INPUT type="radio" name="select" value='<bean:write name="element" property="pk"/>'>
</TD>
<TD width="12%">
<bean:write name="element" property="year" />
</TD>
<TD width="20%">
<bean:write name="element" property="term" />
</TD>
<TD width="50%">
<bean:write name="element" property="name" />
</TD>
<TD width="10%" align="center">
<a href="./editExamNameFind.do?pk=<bean:write name='element' property='pk'/>">
<img border="0" src="<%=request.getContextPath()%>/skin/<bean:write name="user" property="skin"/>/edit.gif" title="<bean:message key='com.oper.edit'/>"/></a>
<a href="./delExamName.do?pk=<bean:write name='element' property='pk'/>">
<img border="0" src="<%=request.getContextPath()%>/skin/<bean:write name="user" property="skin"/>/del.gif" title="<bean:message key='com.oper.delete'/>"/></a>
</TD>
</TR>
<tr>
<td colspan="5">
<table border="0" cellspacing="1" width="100%" align="center" class="tableborder">
<tr class="trHead">
<td width="8%" height="20" align="center">
<bean:message key="com.index"/>
</td>
<td width="12%" align="center">
<bean:message key="numbershowingplan.numberShowings"/>
</td>
<td width="35%" align="center">
<bean:message key="numbershowingplan.beginTime"/>
</td>
<td width="35%" align="center">
<bean:message key="numbershowingplan.beginTime"/>
</td>
<td width="10%" align="center">
<bean:message key="com.oper"/>
</td>
</tr>
<logic:iterate id="rule" name="element" property="numberShowingsPlans" indexId="idxid">
<tr class="tr">
<td width="8%" height="20" align="center">
<bean:write name="idxid"/>
</td>
<td width="12%" align="center">
<bean:write name="rule" property="numberShowings"/>
</td>
<td width="35%" align="center">
<bean:write name="rule" property="beginTime"/>
</td>
<td width="35%" align="center">
<bean:write name="rule" property="endTime"/>
</td>
<td width="10%">
<a href="./editExamNameFind.do?pk=<bean:write name='element' property='pk'/>">
<img border="0" src="<%=request.getContextPath()%>/skin/<bean:write name="user" property="skin"/>/edit.gif" title="<bean:message key='com.oper.edit'/>"/></a>
<a href="./delExamName.do?pk=<bean:write name='element' property='pk'/>">
<img border="0" src="<%=request.getContextPath()%>/skin/<bean:write name="user" property="skin"/>/del.gif" title="<bean:message key='com.oper.delete'/>"/></a>
</td>
</tr>
</logic:iterate>
</table>
</td>
</tr>
</logic:iterate>
</TABLE>
</logic:present>
本文地址:http://www.45fan.com/a/question/69244.html