发布网友 发布时间:2022-04-09 17:28
共2个回答
懂视网 时间:2022-04-09 21:49
<s:iterator var="word" value="#wordList>//其中wordList是与Action中context.put("wordList", wordList);里的list集合相对应的,list装的是数据库东西,word只是个变量名 <s:property value="#word.details"/>//用<s:property取出wordList元素中的details属性, 即数据库中的details字段 </s:iterator>
private String time;
private String details;
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集合接收的是从Dao层传来的数据库内容
context.put("wordList", wordList);
return "word";
}
public static List<Word> getWordList() { Session session=HibernateSessionFactory.getSession(); try { Criteria criteria=session.createCriteria(Word.class); List<Word> word=criteria.list();//获取数据库里的表装到List集合中 session.close(); return word;//返回list集合 } catch (Exception e) { e.printStackTrace(); } return null; }
public class Word implements java.io.Serializable{ private static final long serialVersionUID = 1L; private Integer id; private String time; private String details; public Word() { } //重载构造方法 public Word(String time, String details) { this.time = time; this.details = details; } ...下面省略各个成员的set,get方法 }
现在是hbm.xml,与hibernate.cfg.xml相关文件的配置
//以下是hbm.xml <hibernate-mapping> <!-- 映射数据库的word表 --> <class name="com.model.Word" table="word" catalog="se"> <!-- 映射id字段 --> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="identity" /> </id> <!-- 映射name字段 --> <property name="time" type="java.lang.String"> <column name="time" length="30" not-null="true" /> </property> <!-- 映射pwd字段 --> <property name="details" type="java.lang.String"> <column name="details" length="2000" not-null="true" /> </property> </class> </hibernate-mapping> //以下是cfg.xml <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <!-- 链接地址 --> <property name="connection.url"> jdbc:mysql://localhost:3306/se?useUnicode=true&characterEncoding=UTF-8 </property> <!-- 数据库user --> <property name="connection.username">root</property> <!-- 数据库user密码 --> <property name="connection.password">root</property> <!-- 连接driver --> <property 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> <!-- 映射文件 --> <mapping resource="com/model/Word.hbm.xml" /> </session-factory> </hibernate-configuration>
<action name="wordpage" class="com.action.WordAction"> <result name="word">/user/word.jsp</result> </action>
jsp页面如何遍历数据库的表
标签:cto 密码 property stack jsp catalog name char orm
热心网友 时间:2022-04-09 18:57
jsp中遍历list最常用的办法是用c标签库的foreach来循环输出。 注:items是结果集,all是要遍历的list,x是循环变量也是一个list中的对象 引用标签库 举例如下: 标题:${x.n_title } 作者:${x.n_user }td>