如何使用Mybaits調用數據庫中的存儲過程,下面以Oracle數據庫的爲例:java
1.定時器web
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.javaspring
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.存儲過程見上篇文章apache