java main方法里調用mapper

在main方法中調用mybatis的mapper,一次性執行導入數據功能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<Map<String,Object>> 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();}}}

?

配置文件代碼:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><context:property-placeholder location="classpath:config.properties"/><!-- 掃描注解Bean 采用自定義命名策略工具類 --><context:component-scan base-package="com.runxsoft" name-generator="com.runxsoft.iutils.common.spring.JAnnotationBeanNameGenerator"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!-- 開啟AOP監聽 只對當前配置文件有效 --><aop:aspectj-autoproxy expose-proxy="true"/><!-- 第一個數據源 --><bean id="dataSource_1" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"><!-- 數據源驅動類可不寫,Druid默認會自動根據URL識別DriverClass --><property name="driverClassName" value="${jdbc.driver}" /><!-- 基本屬性 url、user、password --><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><!-- 配置初始化大小、最小、最大 --><property name="initialSize" value="${druid.initialSize}"/><property name="minIdle" value="${druid.minIdle}"/><property name="maxActive" value="${druid.maxActive}"/><!-- 配置獲取連接等待超時的時間 --><property name="maxWait" value="${druid.maxWait}"/><!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒 --><property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" /><!-- 配置一個連接在池中最小生存的時間,單位是毫秒 --><property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" /><property name="validationQuery" value="${druid.validationQuery}" /><property name="validationQueryTimeout" value="${druid.validationQueryTimeout}" /><property name="testWhileIdle" value="${druid.testWhileIdle}" /><property name="testOnBorrow" value="${druid.testOnBorrow}" /><property name="testOnReturn" value="${druid.testOnReturn}" /><property name="removeAbandoned" value="${druid.removeAbandoned}" /><property name="removeAbandonedTimeout" value="${druid.removeAbandonedTimeout}" /><property name="logAbandoned" value="${druid.logAbandoned}" /><!-- 打開PSCache,并且指定每個連接上PSCache的大小 oracle=true mysql=false --><property name="poolPreparedStatements" value="${druid.poolPreparedStatements}" /><property name="maxPoolPreparedStatementPerConnectionSize" value="${druid.maxPoolPreparedStatementPerConnectionSize}" /><!-- 配置監控統計攔截的filters --><property name="filters" value="${druid.filters}" /></bean><!-- 第二個數據源 --><!--<bean id="dataSource_2" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">--><!--&lt;!&ndash; 數據源驅動類可不寫,Druid默認會自動根據URL識別DriverClass &ndash;&gt;--><!--<property name="driverClassName" value="${jdbc2.driver}" />--><!--&lt;!&ndash; 基本屬性 url、user、password &ndash;&gt;--><!--<property name="url" value="${jdbc2.url}"/>--><!--<property name="username" value="${jdbc2.username}"/>--><!--<property name="password" value="${jdbc2.password}"/>--><!--&lt;!&ndash; 配置初始化大小、最小、最大 &ndash;&gt;--><!--<property name="initialSize" value="${druid.initialSize}"/>--><!--<property name="minIdle" value="${druid.minIdle}"/>--><!--<property name="maxActive" value="${druid.maxActive}"/>--><!--&lt;!&ndash; 配置獲取連接等待超時的時間 &ndash;&gt;--><!--<property name="maxWait" value="${druid.maxWait}"/>--><!--&lt;!&ndash; 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒 &ndash;&gt;--><!--<property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />--><!--&lt;!&ndash; 配置一個連接在池中最小生存的時間,單位是毫秒 &ndash;&gt;--><!--<property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />--><!--<property name="validationQuery" value="${druid.validationQuery}" />--><!--<property name="validationQueryTimeout" value="${druid.validationQueryTimeout}" />--><!--<property name="testWhileIdle" value="${druid.testWhileIdle}" />--><!--<property name="testOnBorrow" value="${druid.testOnBorrow}" />--><!--<property name="testOnReturn" value="${druid.testOnReturn}" />--><!--<property name="removeAbandoned" value="${druid.removeAbandoned}" />--><!--<property name="removeAbandonedTimeout" value="${druid.removeAbandonedTimeout}" />--><!--<property name="logAbandoned" value="${druid.logAbandoned}" />--><!--&lt;!&ndash; 打開PSCache,并且指定每個連接上PSCache的大小 oracle=true mysql=false &ndash;&gt;--><!--<property name="poolPreparedStatements" value="${druid.poolPreparedStatements}" />--><!--<property name="maxPoolPreparedStatementPerConnectionSize" value="${druid.maxPoolPreparedStatementPerConnectionSize}" />--><!--&lt;!&ndash; 配置監控統計攔截的filters &ndash;&gt;--><!--<property name="filters" value="${druid.filters}" />--><!--</bean>--><!-- 動態配置數據源 --><bean id ="dataSource" class= "com.runxsoft.iutils.common.datasource.DynamicDataSource" ><property name ="targetDataSources"><map key-type ="java.lang.String"><entry value-ref ="dataSource_1" key= "dataSource_1"></entry ><!--<entry value-ref ="dataSource_2" key= "dataSource_2"></entry >--></map ></property ><property name ="defaultTargetDataSource" ref= "dataSource_1"></property ></bean ><!-- MyBatis begin --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="mapperLocations" value="classpath:/mappings/**/*.xml"/><property name="configLocation" value="classpath:/mybatis-config.xml"></property></bean><!-- 掃描basePackage下所有以@MyBatisDao注解的接口 --><bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /><property name="basePackage" value="com.runxsoft"/><property name="annotationClass" value="com.runxsoft.iutils.common.annotation.MyBatisDao"/></bean><!-- 定義事務 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- 配置 Annotation 驅動,掃描@Transactional注解的類定義事務  --><tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/><!-- MyBatis end --><!-- 配置事務的傳播特性 --><tx:advice id ="txAdvice" transaction-manager="transactionManager"><tx:attributes ><tx:method name ="find*" read-only="true" /><tx:method name ="get*" read-only="true" /><tx:method name ="query*" read-only="true" /><tx:method name ="save*" propagation="REQUIRED" /><tx:method name ="add*" propagation="REQUIRED" /><tx:method name ="update*" propagation="REQUIRED" /><tx:method name ="delete*" propagation="REQUIRED" /></tx:attributes ></tx:advice ><!-- 配置AOP --><aop:config ><!-- 切點 多包配置 execution(* cn.iutils.*.service..*.*(..)) or execution(* com.company.*.service..*.*(..)) --><aop:pointcut expression ="execution(* com.runxsoft.*.*.service..*.*(..))" id= "pointcut" /><aop:advisor advice-ref ="txAdvice" pointcut-ref="pointcut" /></aop:config ><!-- Spring工具 --><bean class="com.runxsoft.iutils.common.spring.SpringUtils"></bean><!-- 調度工廠 --><bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"></bean><!-- 導入shiro配置 --><!--<import resource="classpath:spring-config-shiro.xml"/>--></beans>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/386578.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/386578.shtml
英文地址,請注明出處:http://en.pswp.cn/news/386578.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

已成功拿下字節、騰訊、脈脈offer,滿滿干貨指導

開頭 籠統來說&#xff0c;中年程序員容易被淘汰的原因其實不外乎三點。 1、輸出能力已到頂點。這個人奮斗十來年了&#xff0c;依舊碌碌無為&#xff0c;很明顯這人的天花板就這樣了&#xff0c;說白了&#xff0c;天賦就這樣。 2、適應能力越來越差。年紀大&#xff0c;有家…

ServletRequest HttpServletRequest 請求方法 獲取請求參數 請求轉發 請求包含 請求轉發與重定向區別 獲取請求頭字段...

原文地址:ServletRequest HttpServletRequest 請求方法 獲取請求參數 請求轉發 請求包含 請求轉發與重定向區別 獲取請求頭字段ServletRequest 基本概念 JavaWeb中的 "Request"對象 實際為 HttpServletRequest 或者 ServletRequest, 兩者都為接口服務器接收請求…

c#掃描圖片去黑邊(掃描儀去黑邊)

/// <summary> /// 自動去除圖像掃描黑邊 /// </summary> /// <param name"fileName"></param> public static void AutoCutBlackEdge(string fileName) { //打開圖像 Bit…

已成功拿下字節、騰訊、脈脈offer,算法太TM重要了

一、背景介紹 從實用角度梳理一篇能夠幫大家快速掃盲的CMake基礎教程&#xff0c;也是對我目前負責項目的一次學習總結。既然選擇從項目實用性考慮&#xff0c;下面的講解內容可能并不一定完整&#xff0c;更多的是符合項目目前使用到的一些特性。 接下來正面回答這個問題&am…

SpringBoot2.0 Actuator 監控參數說明

主要內容更 監控參數說明 Maven坐標 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency><groupId>io.micrometer</groupId>&…

帶你一步一步深入Handler源碼,醍醐灌頂!

開頭 最近有粉絲反應&#xff0c;不想做安卓了&#xff0c;有朋友轉到前端了&#xff0c;安卓不行了&#xff0c;問我怎么辦&#xff1f; 自從RN&#xff0c;Weex這種跨平臺編程語言出來以后&#xff0c;安卓將死的言論總是不絕于耳。隨著頗有摧枯拉朽之勢Flutter的出現&…

Spring基于狀態機squirrel-foundation簡單使用

squirrel-foundation的一些使用方法在百度上資料還是比較少&#xff0c;我是根據以下三個大佬寫的文章借鑒的&#xff0c;在這里記錄一下。 1、squirrel-foundation-demo 2、Squirrel使用&#xff08;中文文檔&#xff09; 3、squirrel-foundation狀態機的使用細節 我在這里直接…

記得把每一次面試當做經驗積累,深夜思考

開頭 Android開發&#xff0c;假如開始沒有任何的開發經驗的話&#xff0c; 千萬不要著急&#xff0c;不要想著在短時間內就把一個語言學習好&#xff0c; 因為你之前沒有任何的學習經驗&#xff0c; 在這個過程中需要有耐心地學習完JAVA的基礎知識&#xff0c; 然后才開始踏上…

squirrel-foundation-demo

一個簡單的squirrel-foundation-demo 利用狀態機模擬一個訂單的支付過程。 squirrel-foundation沒有任何嚴重的依賴關系&#xff0c;因此基本上它應該是高度可嵌入的。squirrel-foundation沒有整合spring框架&#xff0c;所以首先要用spring集成squirrel-foundation。spring集成…

MongoDB學習目錄

MongoDB基礎篇 MongoDB 之 $ 關鍵字 python操作MongoDB 轉載于:https://www.cnblogs.com/yanzhi-1996/p/11095016.html

講的真透徹!還有人不知道什么是AndroidX的嗎?已拿offer入職

前言 春招已經接近尾聲了&#xff0c;不知道各位小伙伴有沒有收獲自己心儀的offer呢。筆者疫情被裁后在家LeetCode狂刷了800多題&#xff0c;加之自己以為工作總結的知識、經驗&#xff0c;系統化的整理了一下。在五一期間已經收獲了字節的offer。廢話不多說&#xff0c;下面是…

docker 啟動的 jenkins 中調用宿主機docker進行build

前言 期初有這個需求感覺就跟套娃一樣&#xff0c;你在docker 中調用docker&#xff0c;笑哭……這個也太逗了。 不過的確遇到了&#xff0c;因為jenkins 容器中沒有docker &#xff0c;所以在編譯 docker build 的時候 會出現 docker command 不存在。 好吧&#xff0c;解決他…

Codeforces 773D Perishable Roads 最短路 (看題解)

Perishable Roads 智商題&#xff0c; 不會啊。。 貼個官方題解 https://codeforces.com/blog/entry/51883 #include<bits/stdc.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_p…

Rancher中的服務升級實驗

創建一個空的應用myAPP&#xff0c;在myAPP 應用中&#xff0c;創建一個服務nginx-test&#xff0c;包含2個容器副本&#xff0c;使用nginx:1.13.0鏡像。假設使用一段時期以后&#xff0c;nginx的版本升級到1.13.1了&#xff0c;如何將該服務的鏡像版本升級到新的版本&#xff…

該如何高效實用Kotlin?看這一篇就夠了!

前言 說起程序員人們的第一印象就是工資高、加班兇、話少錢多頭發少。再加上現在科技互聯網公司太吃香&#xff0c;bat、華為小米等公司程序員加班情況被廣泛傳播&#xff0c;程序員用生命在敲代碼的印象刻在了很多人的心里。 與其它行業一樣&#xff0c;凡是有高級和普通&…

apply()與call()

JavaScript中的每一個Function對象都有一個apply()方法和一個call()方法&#xff0c;它們的語法分別為&#xff1a; /*apply()方法*/ function.apply(thisObj[, argArray])/*call()方法*/ function.call(thisObj[, arg1[, arg2[, [,...argN]]]]); 它們各自的定義&#xff1a; a…

Java基于redis實現分布式鎖(SpringBoot)

前言 分布式鎖&#xff0c;其實原理是就是多臺機器&#xff0c;去爭搶一個資源&#xff0c;誰爭搶成功&#xff0c;那么誰就持有了這把鎖&#xff0c;然后去執行后續的業務邏輯&#xff0c;執行完畢后&#xff0c;把鎖釋放掉。 可以通過多種途徑實現分布式鎖&#xff0c;例如…

請談下Android消息機制,復習指南

談起Android框架體系架構&#xff0c;我先提個問&#xff1a;什么是Android框架體系架構 &#xff1f; Android系統構架是安卓系統的體系結構&#xff0c;android的系統架構和其操作系統一樣&#xff0c;采用了分層的架構&#xff0c;共分為四層&#xff0c;從高到低分別是And…

SVN Cannot merge into a working copy that has local modifications

我嘗試了 主支&#xff0c;分支都提交&#xff0c;但是依然無法合并。 最終&#xff0c;我在服務器上將分支刪除&#xff0c;然后主支在拷貝過去。 一&#xff0c;打開服務器資源 二&#xff0c;刪除分支 三&#xff0c;拷貝主支到分支 四&#xff0c;刷新分支&#xff0c;就能…

資深Android開發帶你入門Framework,再不刷題就晚了!

想要成為一名優秀的Android開發&#xff0c;你需要一份完備的知識體系&#xff0c;在這里&#xff0c;讓我們一起成長為自己所想的那樣。 本文參考了目前大部分 Android 應用啟動優化的方案&#xff0c;將大家的方案做一個匯總&#xff0c;如果你有這方面的需求&#xff0c;只…