日期:2014-05-16 浏览次数:20576 次
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true" errorTracingEnabled="true" maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="false" /> <transactionManager type="JDBC"> <dataSource type="SIMPLE"> <property name="JDBC.Driver" value="org.h2.Driver" /> <property name="JDBC.ConnectionURL" value="jdbc:h2:database/h2db" /> <property name="JDBC.Username" value="root" /> <property name="JDBC.Password" value="" /> <property name="Pool.MaximumActiveConnections" value="10" /> <property name="Pool.MaximumIdleConnections" value="5" /> <property name="Pool.MaximumCheckoutTime" value="120000" /> <property name="Pool.TimeToWait" value="500" /> <property name="Pool.PingQuery" value="select 1 from sample" /> <property name="Pool.PingEnabled" value="false" /> <property name="Pool.PingConnectionsOlderThan" value="1" /> <property name="Pool.PingConnectionsNotUsedFor" value="1" /> </dataSource> </transactionManager> <!-- 引入user操作文件 --> <sqlMap resource="sqlmap/user-sql.xml"/> </sqlMapConfig>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="User"> <typeAlias alias="user" type="model.User" /> <select id="getUser" parameterClass="java.lang.String" resultClass="user"> <![CDATA[ select name, sex from t_user where name = #name# ]]> </select> <select id="getAllUser" resultClass="user"> <![CDATA[ select name, sex from t_user ]]> </select> <update id="updateUser" parameterClass="user"> <![CDATA[ UPDATE t_user SET name=#name#, sex=#sex# WHERE id = #id# ]]> </update> <insert id="insertUser" parameterClass="user"> INSERT INTO t_user ( name, sex) VALUES ( #name#, #sex# ) </insert> <delete id="deleteUser" parameterClass="java.lang.String"> delete from t_user where id=#value# </delete> </sqlMap>
package model; import java.io.Serializable; public class User implements Serializable { private static final long serialVersionUID = 1L; private Integer id; private String name; private Integer sex; public User() { } public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Integer getSex() { return this.sex; } public void setSex(Integer sex) { this.sex = sex; } }
import java.io.Reader; import java.sql.SQLException; import java.util.List; import model.User; import com.ibatis.common.resources.Resources; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClientBuilder; /** * * @代码功能:测试demo * @packageName * @file_name h2demo.java * @type_name h2de