目录
(3)配置jdbcTemplate 对象,注入 DataSource
(4)创建service类,创建dao类,在dao 里面注入 jdbcTemplate 对象
1.什么是jdbcTemplate
概念:jdbcTemplate是Spring框架对JDBC进行封装,使用jdbcTemplate 方便实现对数据库进行操作
2.使用前准备工作:
(1)引入相关jar包
通过maven导入
(2)在spring 配置文件配置数据库连接池
相当于把数据导入到一个数据库连接池,在这个池里面进行连接会降低资源消耗
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--数据库连接池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">