Spring JdbcTemplate基于XML文件的CRUD案例
一、SpringJdbcTemplate 所需要的jar包
1.在项目下创建lib文件夹放入需要的jar包
①前缀是spring的可以在spring官网下载
②commons-logging-1.2.jar的包
③数据库的包(我这里用的是mysql的数据库)
二、配置xml文件
1.在src文件夹下创建bean.xml文件
代码如下(示例):bean.xml
1.配置数据源
2.配置JDBC模板
3.配置dao层
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<!-- 1.配置数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 数据库驱动 -->
<property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>
<!-- 连接数据库的url -->
<property name="url"
value="jdbc:mysql://localhost:3306/shop?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"></property>
<!-- 连接数据库的用户名 -->
<