30.31.spring对jdbc的支持jdbcTemplate

  05_ssm基础(四)之Spring与持久层的整合

  使用Spring的JDBC准备:
  1):拷贝jar:
       mysql-connector-java-5.1.11.jar:MySQL驱动包
       spring-jdbc-4.1.2.RELEASE.jar:支持JDBC
       spring-tx-4.1.2.RELEASE.jar: 支持事务
  2): 操作Product对象的DAO实现:
  3):参考文档:参考Spring4.x文档的362页.

   代码:如下

    spring配置文件代码

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xsi:schemaLocation="http://www.springframework.org/schema/beans
 6         http://www.springframework.org/schema/beans/spring-beans.xsd
 7          http://www.springframework.org/schema/context
 8           http://www.springframework.org/schema/context/spring-context.xsd">
 9     <!--  读取配置文件-->
10     <context:property-placeholder location="classpath:db.properties"/>
11     <!--配置dataSources-->
12     <bean >
13         <property name="driverClassName" value="${mysql.driverClass}"/>
14         <property name="url" value="${mysql.JdbcUrl}"/>
15         <property name="username" value="${mysql.User}"/>
16         <property name="password" value="${mysql.Password}"/>
17     </bean>
18 
19     <bean >
20         <property name="dataSource" ref="dataSource"/>
21     </bean>
22 </beans>
View Code

相关文章: