- Spring +JDBC配置与使用
- 添加Spring依赖
- 添加mysql依赖
- 创建person类
- 创建dao包
- 创建数据库表
- 测试方法
- 删、查、改
mysql安装可以参考这篇文章
新建spring项目(含导入spring依赖)
Spring第一讲—Spring入门案例
添加mysql依赖org.springframework spring-core 5.3.8 org.springframework spring-beans 5.3.8 org.springframework spring-context 5.3.8 org.springframework spring-context-support 5.2.12.RELEASE org.springframework spring-expression 5.3.8 commons-logging commons-logging 1.2
mysql mysql-connector-java 8.0.20 org.springframework spring-jdbc 5.3.8 org.springframework spring-tx 5.3.8 org.springframework spring-aop 5.3.8
spring容器中创建DriverManagerDataSource和JdbcTemplate对象
创建person类
快速生成get和set方法:
右键---->generate---->Getter and Setter---->按住Shift后全选----->OK
ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("applicationContext.xml");
PersonDao personDao = (PersonDao) applicationContext.getBean("personDao");
personDao.addPerson("text123",20);
查看数据库表(需要刷新)
增加数据就成功了
测试



