Spring中的JDBCTemplate使用
数据库准备:
创建数据库

创建表:

Java代码:
1、创建web 工程 springJdbcTemplate
2、添加Spring能力 在此需要将jdbc包也同时加入


3、配置上mysql的连接驱动(拷贝mysql驱动包,如果不拷贝报错很诡异)
在applicationContext.xml中进行配置
在beans标签中填写
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/myspringjdbcdb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
4、创建包结构并且写出类(每个类中可以没内容)

5、每个类中的源代码
UserDao.java

UserDaoImp.java

此项写完填写在applicationContext.xml中进行配置
在beans标签中填写

User.java

每个成员变量都写上get和set方法
并且在此类中还要加入
此项写完填写在applicationContext.xml中进行配置
在beans标签中填写

测试类TestAction.java

打印出结果:
