Mybatis stored procedure call

How to use Mybaits to call stored procedures in the database, the following is an example of the Oracle database:

1. timer

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 * * * ?") //execute every 2 minutes

    public void taskCycle(){
        postInfoDao.callMergePost ();
        System.out.println("Synchronization post end");
        officeInfoDao.callMergeOffice();
        System.out.println("Synchronous organization ended");
        personAchieveInfoDao.callMergeArchievemets();
        System.out.println("Synchronization performance ended");
        synchroInfoService.synchroUser();
        System.out.println("Synchronization staff ended");
    }

}

2. Take the synchronization organization as an example 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 mapping file

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

4. See the previous article for stored procedures

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325853398&siteId=291194637