Mybatis存储过程调用

如何使用Mybaits调用数据库中的存储过程,下面以Oracle数据库的为例:

1.定时器

package com.tepusoft.modules.synchr.task;

import com.tepusoft.modules.synchr.dao.OfficeInfoDao;
import com.tepusoft.modules.synchr.dao.PersonAchieveInfoDao;
import com.tepusoft.modules.synchr.dao.PostInfoDao;
import com.tepusoft.modules.synchr.service.OfficeInfoService;
import com.tepusoft.modules.synchr.service.SynchroInfoService;
import com.tepusoft.modules.synchr.web.SynchroInfo;
import com.tepusoft.modules.sys.dao.PostDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * Created by ltx on 2017/9/6.
 */
@Service
@Lazy(false)
public class SynchroTask {
    @Autowired
    private SynchroInfoService synchroInfoService;
    @Autowired
    private OfficeInfoDao officeInfoDao;
    @Autowired
    private PostInfoDao postInfoDao;
    @Autowired
    private PersonAchieveInfoDao personAchieveInfoDao;

    @Scheduled(cron="0 */1 * * * ?") //间隔2分执行

    public void taskCycle(){
        postInfoDao.callMergePost();
        System.out.println("同步岗位结束");
        officeInfoDao.callMergeOffice();
        System.out.println("同步组织结束");
        personAchieveInfoDao.callMergeArchievemets();
        System.out.println("同步绩效结束");
        synchroInfoService.synchroUser();
        System.out.println("同步人员结束");
    }

}

2.拿同步组织为例  OfficeInfoDao.java

package com.tepusoft.modules.synchr.dao;

import com.tepusoft.common.persistence.annotation.MyBatisDao;
import com.tepusoft.modules.synchr.entity.OfficeInfo;
import com.tepusoft.modules.synchr.entity.UserInfo;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author XuYunXuan
 * @ClassName: OfficeInfoDao
 * @Description:
 * @date 2017-09-01 10:46
 */
@MyBatisDao
public interface OfficeInfoDao extends BaseDao<OfficeInfo>{
    void callMergeOffice();
}

3.officeInfo.xml映射文件

<update id="callMergeOffice" statementType="CALLABLE">
    <![CDATA[
      {call fn_merge_office}
      ]]>
</update>

4.存储过程见上篇文章

猜你喜欢

转载自my.oschina.net/u/3409039/blog/1552951