rt。。。。。
代码如下:
BookDao类:
public List<Book> queryAll(){
List<Book> list=null;
String hql="from Book as b order by b.id";
Query query=session.createQuery(hql);
list=query.list();
return list;
}
BookAction类:
//查找全部
public String list(){
list=new BookDao().queryAll();
return SUCCESS;
}
listBooks页面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>所有图书</title>
</head>
<body>
<h1>所有图书</h1>
<table>
<tr>
<td width="60">ID</td>
<td width="100">书名</td>
<td width="60">价格</td>
<td width="60"> </td>
</tr>
<s:iterator value="books">
<tr>
<td>
<a href="<s:url action="editbook%{id}"/>"><s:property value="id" /></a>
</td>
<td>
<s:property value="name" />
</td>
<td>
<s:property value="price" />
</td>
<td>
<a href="<s:url action="deletebook%{id}"/>">删除</a>
</td>
</tr>
</s:iterator>
</table>
<p>
<a href="<s:url action="editbook" includeParams="none"/>">创建新的图书</a>
</body>
</html>
struts2配置文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"></include>
<constant name="struts.i18n.encoding" value="gbk"/>
<package name="default" extends="struts-default">
<!-- 列出所有图书 -->
<action name="listbook" class="com.pb.action.BookAction" method="list">
<result>listbooks.jsp</result>
<interceptor-ref name="basicStack"></interceptor-ref>
</action>
<!-- 分类的创建和更新 -->
<action name="editbook*" class="com.pb.action.BookAction">
<param name="id">{1}</param>
<result name="success">editBook.jsp</result>
<interceptor-ref name="static-params"></interceptor-ref>
<interceptor-ref name="basicStack"></interceptor-ref>
</action>
<!-- 保存新创建的分类和更新后的分类 -->
<action name="savebook" class="com.pb.action.BookAction" method="save">
<result name="input">editBook.jsp</result>
<result type="redirect">listbook.action</result>
</action>
<!-- 删除分类 -->
<action name="deletebook*" class="com.pb.action.BookAction" method="delete">