1、在applicationContext.xml做如下配置:
a.引入数据源属性文件:
<!-- 引入数据源属性文件jdbc.properties -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
属性文件中声明:
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=//数据库URL
jdbc.username=//
jdbc.password=//
b.配置数据源连接池:
<!-- 配置数据源连接池 (jotm) -->
<bean id="oracleDS" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
<property name="dataSource">
<bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
<property name="transactionManager" ref="jotm" />
<property name="driverName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
</bean>
</property>
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
3.MyBatis :
<!-- mybatis配置源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="oracleDS" />
<property name="configLocation" value="classpath:SqlMapConfig.xml" />
</bean>
a.SqlMapConfig.xml
<configuration>
<typeAliases>
<!-- 给具体的实例类赋简化名-->
<typeAlias alias="DlssVo" type="com.sinosoft.perfect.shsjgl.facilities.vo.DlssVo" />
</typeAliases>
<mappers>
<!-- 具体映射文件-->
<mapper resource="com/sinosoft/perfect/shsjgl/place/mapper-shsjgl-place.xml"/>
</mappers>
</configuration>
b.mapper-shsjgl-place.xml
<mapper>
<!-- type即上面说的实例类简化名 -->
<!-- id唯一标识 -->
<resultMap type="GhVO" id="GhVORMap">
<result column="ID" property="id" jdbcType="VARCHAR" />
</resultMap>
<!-- 查询 -->
<!-- parameterType:传入参数 -->
<!-- resultMap:返回类型 -->
<select id="selectTShsjglGh" parameterType="GhVO" resultMap="GhVORMap">
SELECT ID, HBM, ZBM, SSZID, DYH, LCH, FH, HX, ZT, FZLX, FZXM, FZSFZH,FZLXFS, DZ, BZ
FROM T_SHSJGL_GH
<where>
<if test="id != null and id != ''">
ID=#{id}
</if>
</where>
</select>
<!-- 插入 -->
<!-- #{id:VARCHAR}:不能有空格 -->
<insert id="insertTShsjglGh" parameterType="GhVO">
INSERT INTO T_SHSJGL_GH (ID, HBM, ZBM,SSZID, DYH, LCH, FH, HX, ZT,FZLX, FZXM, FZSFZH,FZLXFS, DZ, BZ)
VALUES ( #{id:VARCHAR},#{hbm:VARCHAR },#{zbm:VARCHAR},#{sszid:VARCHAR},#{dyh:INTEGER},#{lch:INTEGER},#{fh:VARCHAR},#{hx:VARCHAR},#{zt:VARCHAR},#{fzlx:VARCHAR},#{fzxm:INTEGER},#{fzsfzh:VARCHAR},#{fzlxfs:VARCHAR},#{dz:VARCHAR},#{bz:VARCHAR} )
</insert>
<!-- 更新 -->
<update id="updateTShsjglGh" parameterType="GhVO">
UPDATE T_SHSJGL_GH
<set>
<if test="hbm != null">
HBM = #{hbm},
</if>
</set>
<where>
ID=#{id}
</where>
</update>
<!-- 删除 -->
<delete id="deleteTShsjglGh" parameterType="GhVO">
DELETE FROM T_SHSJGL_GH
<where>
<if test="id != null and id != ''">
ID = #{id}
</if>
</where>
</delete>
</mapper>