数据库链接对象JdbcDaoSupport

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a4171175/article/details/82928939

 

原生的是根据配置文件,将jdbc模板加载到spring容器中。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd ">

<!-- 指定spring读取db.properties配置 -->
<context:property-placeholder location="classpath:db.properties"  />

<!-- 1.将连接池放入spring容器 -->
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >
	<property name="jdbcUrl" value="${jdbc.jdbcUrl}" ></property>
	<property name="driverClass" value="${jdbc.driverClass}" ></property>
	<property name="user" value="${jdbc.user}" ></property>
	<property name="password" value="${jdbc.password}" ></property>
</bean>


<!-- 2.将JDBCTemplate放入spring容器 -->
<bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
	<property name="dataSource" ref="dataSource" ></property>
</bean>

<!-- 3.将UserDao放入spring容器 -->
<bean name="userDao" class="cn.itcast.a_jdbctemplate.UserDaoImpl" >
	<!-- <property name="jt" ref="jdbcTemplate" ></property> -->
	<property name="dataSource" ref="dataSource" ></property>
</bean>
	

</beans>

 原生的是左边,datasoure(数据库,连接池)=》jdbc模板接口,jdbc对象=》实现jdbc模板

现在通过继承了jdbcDaoSupport,可以根据连接池自动创建jdbc对象,以及模板。省去了大部分操作/

猜你喜欢

转载自blog.csdn.net/a4171175/article/details/82928939