1、创建包
scr文件夹下
test.dao
Dao.java
package test.dao;
public interface Dao {
/** 插入批量数据 */
public void addInfo();
}
test.mapping
Dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="test.dao.Dao">
<insert id="addInfo">
INSERT INTO
TBL_INFO
(
MOBIL_NO,
NAME
)
VALUES
(
'17557677676',
'name'
)
</insert>
</mapper>
test.service
Service.java
package test.service;
public interface Service {
public void process() throws Throwable;
}
test.service.impl
ServiceImpl.java
package test.service.impl;
import javax.annotation.Resource;
import test.dao.Dao;
import test.service.Service;
public class ServiceImpl implements Service {
@Resource
private Dao infoDao;
@Override
public void process() throws Throwable {
try {
System.out.println("运行程序*********");
infoDao.addInfo();
} catch (Throwable e) {
throw e;
}
}
}
test.task
Task.java
package test.task;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import test.service.Service;
public class Task {
private static ApplicationContext context;
public static void main(String[] args) {
try {
context = new ClassPathXmlApplicationContext("applicationContext.xml");
Service infoService = context.getBean("infoService", Service.class);
infoService.process();
// 需要进行修眠一段时间,确保全部执行完成
System.exit(0);
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
}
}
test.utils
2、导入包说明
(1)公用包
commons-logging-1.1.1jar
commons-collections-3.2.jar
commons-dbcp-1.4.jar
commons-pool2-2.4.2.jar
commons-pool-1.5.6.jar
ognl-3.0.1.jar
javassist-3.3.jar
(2)spring相关包
spring-aop-4.0.7.jar
spring-beans-4.0.7.jar
spring-context-4.0.7.jar
spring-core-4.0.7.jar
spring-expression-4.0.7.jar
spring-jdbc-4.0.7.jar
spring-orm-4.0.7.jar
spring-tx-4.0.7.jar
spring-web-4.0.7.jar
aopalliance-1.0.jar
aspectjweaver.jar
(3)mybatis相关包
mybatis-3.2.5.jar
mybatis-spring-1.2.2jar
(4)db2包
db2jcc4.jar