JAva mainメソッドでmapperを呼び出す

16406 ワード

JAva mainメソッドでmapperを呼び出す
mainメソッドでmybatisのmapperを呼び出し、データのインポート機能を一度に実行
JAvaコード
package com.runxsoft.test;

import com.runxsoft.iutils.common.utils.UserUtils;
import com.runxsoft.superwe.base.SqlVo;
import com.runxsoft.superwe.base.mapper.ProtogenesisMapper;
import com.runxsoft.superwe.valueCard.Constants;
import com.runxsoft.superwe.valueCard.mapper.CardInfoMapper;
import com.runxsoft.superwe.valueCard.mapper.CardTypeMapper;
import com.runxsoft.superwe.valueCard.mapper.CustomerInfoMapper;
import com.runxsoft.superwe.valueCard.model.Bonus;
import com.runxsoft.superwe.valueCard.model.CardInfo;
import com.runxsoft.superwe.valueCard.model.CardType;
import com.runxsoft.superwe.valueCard.model.CustomerInfo;
import com.runxsoft.superwe.valueCard.model.CustomerInfoExample;
import com.runxsoft.superwe.valueCard.service.CustomerInfoService;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ImprotMain {

    
    public static void main(String[] args) {

        ApplicationContext context=new ClassPathXmlApplicationContext("spring-config-imp.xml");
        BeanFactory factory = (BeanFactory) context;
        CustomerInfoMapper customerInfoMapper=factory.getBean(CustomerInfoMapper.class);
        ProtogenesisMapper protogenesisMapper = factory.getBean(ProtogenesisMapper.class);
        CardTypeMapper cardTypeMapper = factory.getBean(CardTypeMapper.class);
        CardInfoMapper cardInfoMapper = factory.getBean(CardInfoMapper.class);
        try {
       //       mapper   
            List> results = protogenesisMapper.selectBySql(
                    new SqlVo("select usAccounts,usNumber,usName,departname,usMoney, " +
                            "ifnull(ROUND((select sum(crMoney) from old_chargerecord cr where cr.crAccounts = ubi.usAccounts),2),0) as consumedMoney, " +
                            "ROUND((usMoney + ifnull((select sum(crMoney) from old_chargerecord cr where cr.crAccounts = ubi.usAccounts),0)),0) as totalMoney," +
                            "usCardNo, usRegisterDate ,ushandtel,usIdentityCardNo,usSex " +
                            "from old_userbasicinfo ubi " +
                            "left join old_T_S_Department on DepartID = usDepartmentNo  " +
                            "where ifnull(usNumber,'')<>'' " +
                            "and ifnull(usCardNo,'0')<>'0' " +
                            "and usMoney > 0  " +
                            "order by ubi.usName"));
            String userName = "";
            CardInfo cardInfo = null;
            Long customerId = 0L;
           
            System.out.println(results.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}

 
プロファイルコード:


       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    

    
    package="com.runxsoft" name-generator="com.runxsoft.iutils.common.spring.JAnnotationBeanNameGenerator">
        
    

    
    


    
    class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        
        
        
        
        
        

        
        
        
        

        
        
        
        

        
        

        
        
        
        
        
        
        
        

        
        
        

           
        
    

    
    
        
        
        
        
        
        

        
        
        
        

        
        
        
        

        
        

        
        
        
        
        
        
        
        

        
        
        

        
        
    

    
    class= "com.runxsoft.iutils.common.datasource.DynamicDataSource" >
        
            
                
                
            
        
        
    

    
    class="org.mybatis.spring.SqlSessionFactoryBean">
        
        
        
    
    
    
    class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        
        
        
    
    
    
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        
    
    
    
    class="true"/>
    

    
    
        
            
            
            
            
            
            
            
        
    

    
    
        
        
        
    


    
    class="com.runxsoft.iutils.common.spring.SpringUtils">

    
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    

    
    


 
posted @
2018-07-11 17:03ピーナッツ福読(
...) コメント(
...) コレクションの編集