spring-mybatis框架搭建

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值