本文出处:http://morner.spaces.live.com/blog/cns!81A0B358EC451EFB!221.entry
<form-bean name="accountBean" type="com.ibatis.jpetstore.presentation.AccountBean"/>
<form-bean name=" catalogBean" type="com.ibatis.jpetstore.presentation.CatalogBean"/>
<form-bean name="cartBean" type="com.ibatis.jpetstore.presentation.CartBean"/>
<form-bean name="orderBean" type="com.ibatis.jpetstore.presentation.OrderBean"/>
</form-beans>
name=" catalogBean" scope="session"
validate="false">
<forward name="success" path="/catalog/SearchProducts.jsp"/>
</action>
控制跳转到 catlogBean中的 searchProdusts方法
if (keyword == null || keyword.length() < 1) {
setMessage("Please enter a keyword to search for, then press the search button.");
return FAILURE;
} else {
productList = catalogService.searchProductList(keyword.toLowerCase());
return SUCCESS;
}
}
public class DaoConfig {
private static final String resource = "com/ibatis/jpetstore/persistence/dao.xml";//读取对应配置文件
private static final DaoManager daoManager;
static {
try {
daoManager = newDaoManager(null);
Properties props = Resources.getResourceAsProperties("properties/database.properties");//数据库配置文件
String url = props.getProperty("url");
String driver = props.getProperty("driver");
String username = props.getProperty("username");
String password = props.getProperty("password");
if (url.equals("jdbc:hsqldb:mem:jpetstore")) {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url, username, password);
try {
ScriptRunner runner = new ScriptRunner(conn, false, false);
runner.setErrorLogWriter(null);
runner.setLogWriter(null);
runner.runScript(Resources.getResourceAsReader("ddl/hsql/jpetstore-hsqldb-schema.sql"));//建表
runner.runScript(Resources.getResourceAsReader("ddl/hsql/jpetstore-hsqldb-dataload.sql"));
} finally {
conn.close();
}
}
} catch (Exception e) {
throw new RuntimeException("Description. Cause: " + e, e);
}
}
public static DaoManager getDaoManager() {
return daoManager;
}
public static DaoManager newDaoManager(Properties props) {
try {
Reader reader = Resources.getResourceAsReader(resource);
return DaoManagerBuilder.buildDaoManager(reader, props);
} catch (Exception e) {
throw new RuntimeException("Could not initialize DaoConfig. Cause: " + e, e);
}
}
}
com/ibatis/jpetstore/persistence/dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE daoConfig
PUBLIC "-//ibatis.apache.org//DTD DAO Configuration 2.0//EN"
"http://ibatis.apache.org/dtd/dao-2.dtd">
<daoConfig>
<context>
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource"
value="com/ibatis/jpetstore/persistence/sqlmapdao/sql/sql-map-config.xml"/>
</transactionManager>
<dao interface="com.ibatis.jpetstore.persistence.iface.ItemDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.ItemSqlMapDao"/>
<dao interface="com.ibatis.jpetstore.persistence.iface.SequenceDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.SequenceSqlMapDao"/>
<dao interface="com.ibatis.jpetstore.persistence.iface.AccountDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.AccountSqlMapDao"/>
<dao interface="com.ibatis.jpetstore.persistence.iface.CategoryDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.CategorySqlMapDao"/>
<dao interface="com.ibatis.jpetstore.persistence.iface.ProductDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.ProductSqlMapDao"/>
<dao interface="com.ibatis.jpetstore.persistence.iface.OrderDao"
implementation="com.ibatis.jpetstore.persistence.sqlmapdao.OrderSqlMapDao"/>
</context>
</daoConfig>