Posted on 2007-01-15 20:39
sugo 閱讀(312)
評論(0) 編輯 收藏
???? 使用hibernate的hql查詢,當指定某些字段時,一行數(shù)據(jù)此時得到的是相應的一個數(shù)組。而字段全部查詢得到的是一個pojo對象。
???? 使用struts的邏輯標簽顯示時,如果得到的是一個pojo對象,可以使用<logic:iterate>,也可以使用<logic present>使用的時候不用再定義id,name屬性即為request或者session里存儲的對象的別名。然后使用<bean:write>定義兩個屬性name和logic標簽的name一樣,property為對應的類中定義的成員變量名字。
???? 如果得到的是數(shù)組的集合,則需要<logic:iterate>嵌套。例如:
??? <logic:iterate name="du" id="indiv" scope="session">
??? ???? <logic:iterate name="indiv" id="tiny">
????????????? <bean:write name="tiny" />
??????? </logic:iterate>
??? </logic:iterate>
???? 注(個人認為):可以看到規(guī)律,下一層的name為上層的id。
??? 得到的是集合,如List 或者Vector等。例如:
?? <logic:iterate scope="session" id="du" name="dlist">
????? <bean:write name="du" property="wdate" />
????? <bean:define id="text" name="du" property="content" type="String"/>
??????<html:link href="modify.do" paramId="id" paramName="du" paramProperty="id" linkName="mod"? />
????? <html:button property="modify" onclick="mod.click()" value="modify" />
????? <html:textarea property="content" value="<%= text %>"></html:textarea><br>
????? <bean:write name="du" property="username" />
????? <bean:write name="du" property="weather" /> <br>
????? <html:link href="modify.do?manipulate=delete" paramId="id" paramName="du" paramProperty="id"??????? linkName="del"? />
????? <html:button property="delete" onclick="del.click()" value="delete" />
??? </logic:iterate>
??? 例子中還包括在一個組件中填值,使用<bean:define>標簽,可以得到一個對象,id就是對象的引用。
????<html:link>的linkName相當于超鏈接<a href="">中的id屬性,<html:link>的page和href的不同,page需要相對路徑,url前面需要加上/,href則不用。<html:link>參數(shù)傳遞,如果確定需要傳遞的參數(shù),直接跟在url后面即可。如果是動態(tài)的,則需要paramId, paramName, paramProperty 。第一個為參數(shù)名稱,第二個為存儲的對象的名字,如在request、session中存儲的名字,第三個就是這個對象里面的成員變量。多個參數(shù)一般使用HashMap。
??? Struts中的action,即便是不想用ActionForm,也需要在action的配置屬性里寫入,否則會出現(xiàn)空值的問題,今天遇到了,所以定義DynaActionForm還是必要的。
??? hibernate一般的數(shù)據(jù)庫操作都通過session來進行,我把所有涉及的操作都寫成了一個ObjectDAO,比較方便操作。