I am a beginner, the following is the rookie in the actual use of the record, the great God can skip, of course, also welcome guidance twos
- Starting with the JSP page, here is the
<s:iterator var= "word" value= "#wordList >//where wordList is associated with the action Context.put (" WordList ", wordList), the list collection in the , list is a database thing, Word is just a variable name <s:property value= "#word. Details"/>//takes out the details property in the wordlist element with <s:property, that is, the details field in the database </s:iterator>
Private String time;
Private stringdetails;
Public String GetTime () {
return time;
}
public void SetTime (String time) {
This.time = time;
}
Public String getdetails () {
return details;
}
public void Setdetails (String details) {
This.details = details;
}
Public String showwordlist () throws exception{
Actioncontext Context=actioncontext.getcontext ();
List<word> wordlist=worddao.getwordlist ();//list collection receives database content from the DAO layer
Context.put ("WordList", wordList);
return "word";
}
- Then there's the DAO layer.
Public StaticList<word>Getwordlist () {Session session=hibernatesessionfactory.getsession (); Try{Criteria=session.createcriteria (Word.class); List<Word> word=criteria.list ();//get the table in the database into the list set session.close (); returnword;//returns the list collection}Catch(Exception e) {E.printstacktrace (); } return NULL; }
- Then there's the model layer.
Public classWordImplementsjava.io.serializable{Private Static Final LongSerialversionuid = 1L; PrivateInteger ID; PrivateString time; PrivateString details; PublicWord () {}//Overloaded Construction Methods PublicWord (string time, string details) { This. Time =Time ; This. Details =details; }... The Set,get method for each member is omitted below}
Now it's hbm.xml. Configuration of files related to Hibernate.cfg.xml
//here are the Hbm.xmlclassName= "Com.model.Word" table= "Word" catalog= "se" > <!--Mapping ID field--<id name= "id" type= "java.lang.i Nteger "> <column name=" id "/> <generatorclass= "Identity"/> </id> <!--map Name field--<property name= "Time" type= "java.lang.String "> <column name=" Time "length=" not-NULL= "true"/> </property> <!--map pwd field--<property name= "Details" type= "java.lang.St Ring "> <column name=" Details "length=" not-NULL= "true"/> </property> </class>//here are the Cfg.xmlOrg.hibernate.dialect.MySQLDialect</property> <!--link address--<property name= "Connection.url" >Jdbc:mysql://Localhost:3306/se?useunicode=true&characterencoding=utf-8</property> <!--database user--<property name= "Connection.username" >root</property> <!-- Database user Password--<property name= "Connection.password" >root</property> <!--Connection Driver--<PR Operty name= "Connection.driver_class" >Com.mysql.jdbc.Driver</property> <property name= "Myeclipse.connection.profile" >Com.mysql.jdbc.Driver</property> <property name= "Show_sql" >true</property> <property name= "Format_sql" >true</property> <!--map Files--<mapping resource= "Com/model/word.hbm.xml"/></session-factory>< ;/hibernate-configuration>
- Next is the Struts.xml configuration.
class= "Com.action.WordAction" > <result name= "word" >/user/word.jsp</result></ Action>
How JSP pages traverse a table in a database