ibatis 框架需要类和xml文件配置
来源:互联网 发布:联通和电信光纤端口 编辑:程序博客网 时间:2024/06/04 19:28
IBatisUtils .java
package dao;
import java.io.IOException;
import java.io.Reader;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
public class IBatisUtils {
private static SqlMapClient sqlMapClient;
static{
try {
Reader reader=Resources.getResourceAsReader("SqlMapConfig.xml");
sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
throw new RuntimeException("在构件SqlMapClient实例的时候发生了异常!" + e, e);
}
}
public static SqlMapClient getSqlMapClient(){
return sqlMapClient;
}
}
person_SqlMap.xml
<?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="Person">
<!-- 定义该映射文件的Cache机制 -->
<cacheModel type="LRU" id="userCache">
<!-- 设定缓存存活的时间 -->
<flushInterval hours="24"/>
<!-- 设定指定的操作,清空缓存 -->
<flushOnExecute statement="updateUser"/>
<!-- 设定缓存的容量(对象) -->
<property name="size" value="1000"/>
</cacheModel>
<resultMap class="po.Person" id="map_person">
<result property="id" column="per_id"></result>
<result property="firstName" column="per_first_name"></result>
<result property="lastName" column="per_last_name"></result>
<result property="birthDate" column="per_birth_date"></result>
<result property="weightInKilograms" column="per_column_kg"></result>
<result property="heightInMeters" column="per_height_m"></result>
</resultMap>
<select id="selectAllPersons" resultClass="po.Person">
SELECT * FROM ACCOUNT
</select>
<select id="getPersonById" parameterClass="Integer" resultClass="po.Person">
SELECT PER_ID as id, PER_FIRST_NAME as firstName, PER_LAST_NAME
as lastName, PER_BIRTH_DATE as birthDate, PER_WEIGHT_KG as
weightInKilograms, PER_HEIGHT_M as heightInMeters FROM PERSON
WHERE PER_ID = #value#
</select>
<insert id="insertPerson" parameterClass="po.Person">
INSERT INTO PERSON VALUES (#id#, #firstName#, #lastName#,
#birthDate#, #weightInKilograms#, #heightInMeters#)
</insert>
<update id="updatePerson" parameterClass="po.Person">
UPDATE PERSON SET PER_FIRST_NAME = #firstName#, PER_LAST_NAME =
#lastName#, PER_BIRTH_DATE = #birthDate#, PER_WEIGHT_KG =
#weightInKilograms#, PER_HEIGHT_M = #heightInMeters# WHERE
PER_ID = #id#
</update>
<delete id="deletePerson" parameterClass="po.Person">
DELETE PERSON WHERE PER_ID = #id#
</delete>
</sqlMap>
SqlMapConfig.xml
<?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>
<!-- Configure a built-in transaction manager. If you're using an
app server, you probably want to use its transaction manager
and a managed datasource -->
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost:3306/jq115"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="3306"/>
</dataSource>
</transactionManager>
<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="po/person_SqlMap.xml"/>
</sqlMapConfig>
- ibatis 框架需要类和xml文件配置
- ibatis框架SqlMapConfig.xml文件配置
- springmvc+ibatis框架搭建(xml配置)
- Ibatis中xml文件的常用配置
- build.xml 和iBATIS 配置 build.properties
- spring 的核心框架包和XML文件配置
- 关于搭建restful web service + springMVC + ibatis/hibernate的整合和XML配置意思和ssh+springMVC框架搭建
- ibatis SqlMapConfig.xml 配置
- ibatis pojo xml配置
- ibatis - sqlMapConfig.xml配置
- Ibatis访问xml文件
- ibatis配置xml文件中CDATA的用法
- ibatis配置xml文件中CDATA的用法
- ibatis学习之sqlMapConfig.xml文件配置详解
- ibatis中的SQLMapConfig.xml配置及.properties文件的使用
- 基于Annotation注解整合SSH框架和基于XML文件配置Bean整合SSH框架
- 基于Annotation注解整合SSH框架和基于XML文件配置Bean整合SSH框架
- ibatis映射文件配置..
- 网络系统实验:交换机的配置
- GridView实现用“...”代替超长字符串
- Canny边缘检测算法原理及其VC实现详解(一)
- 谈谈你对云计算技术的看法
- [Lab2]linux下的进程
- ibatis 框架需要类和xml文件配置
- Android 开发平台的搭建
- build ffmpeg for armv7 and armv7s ( 本人尚未验证)
- MyISAM表的缓存
- double转化成string string 转化成Csting
- 计算几何POJ1269
- Linux 系列(一) - 基本命令
- LC振荡电路
- RedHat 6 配置网卡team