通过Spring的IOC控制完成druid数据库的基本操作案例

Bonita ·
更新时间:2024-09-20
· 655 次阅读

1 通过Maven的形式导入用到的JAR包坐标

org.springframework spring-context 5.0.2.RELEASE commons-logging commons-logging 1.2 log4j log4j 1.2.12 junit junit 4.12 test com.alibaba druid 1.1.10 mysql mysql-connector-java 5.1.6

2 查看MySQL的表结构
在这里插入图片描述

7 编写测试类

@Test public void test3(){ ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml"); MyIpServiceImpl myipservice = ac.getBean("myipservice", MyIpServiceImpl.class); List all_ip = myipservice.getAll_IP(); for(MyIp myIp:all_ip){ System.out.print(myIp.getIp_address()+" "); System.out.println(myIp.getIp_date()); } }

8 运行结果
在这里插入图片描述


作者:风学长



spring druid ioc

需要 登录 后方可回复, 如果你还没有账号请 注册新账号