import cn.jpp.model.*;
import cn.jpp.service.impl.AllService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Component
public class main {
//读取console.xml
private static ApplicationContext applicationContext = new ClassPathXmlApplicationContext("console.xml");
//获取服务
private static AllService allService=(AllService)applicationContext.getBean("allService");
public static void main(String[] args) {
//StInstance
List<StInstance2> user = allService.getList();
// allService.insert(user);
//XtInstance
List<OldXtInstance> oldXtInstanceList = allService.getXtInstance();
// allService.insertXtInstance(oldXtInstanceList);
//UT_GW_ARCHIVE_INCEPT
List<oldAchiveIncept> oldAchiveIncept = allService.getAchiveIncept();
// allService.insertAchiveIncept(oldAchiveIncept);
//ST_DYNAMIC_RESOURCE
List<oldStDynamicResource> oldStDynamicResourceList = allService.getResourceList();
// allService.insertStDynamicResource(oldStDynamicResourceList);
//st_work_item_hist
List<oldStWorkItemHist> oldStWorkItemHistList = allService.getOldStWorkItemHist();
// allService.insertWorkItemHistList(oldStWorkItemHistList);
//Ut_file
List<oldFile> oldFiles = allService.getOldFiles();
}
}
/**console.xml
<?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: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/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="cn.jpp"/>
<import resource="applicationContext.xml"/>
<bean id="newFile" class="cn.jpp.model.newFile"></bean>
</beans>
*/
/** applicationgContext.xml
<?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: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-3.1.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">
<!-- 加载properties文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<!-- 配置数据源
com.alibaba.druid.pool.DruidDataSource
org.apache.commons.dbcp.BasicDataSource-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
<!-- mybatis和spring完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 扫描model包 -->
<property name="typeAliasesPackage" value="cn.jpp.model"/>
<!-- 扫描sql配置文件:mapper需要的xml文件-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- Mapper动态代理开发,扫描dao接口包-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 给出需要扫描Dao接口包 -->
<property name="basePackage" value="cn.jpp.dao"/>
</bean>
<!-- 事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--数据库连接池-->
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
*/
本文介绍了一个使用Spring框架整合MyBatis的示例,展示了如何通过Spring的依赖注入和事务管理特性来操作数据库。代码中包含了读取配置、创建数据源、设置SqlSessionFactory、扫描DAO接口以及进行数据库操作的过程。
399

被折叠的 条评论
为什么被折叠?



