Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据

mybatis plus第五讲 spring-mybatis.xml文件

注意红色的地方就是mybatis plus配置的地方。实际上是用mybatis plus接管了原生态mybatis的sqlSessionFactory

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<!-- @Autowired @Required @Resource @PostConstruct @PreDestroy -->
<!-- 当使用<context:component-scan/>后 -->
<!-- 即可将<context:annotation-config/>省去  -->
<context:component-scan base-package="com.vv.*" />

<!--接管数据库-->
<bean id="jdbcDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatisplus? useUnicode=true&amp;characterEncoding=UTF8" />                
<property name="username" value="root"/>
<property name="password" value="12345678"/>
</bean> 
 
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
       <property name="dataSource" ref="jdbcDataSource"/>
       <!-- 自动扫描Mapping.xml文件 -->
       <property name="mapperLocations" value="classpath:com/vv/mapping/*.xml" />
       <!-- 加载mybatis主配置文件 -->
       <!-- property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/ -->
       <!-- property name="typeAliasesPackage" value="com.baomidou.springmvc.model.*"/ -->
       <property name="plugins">
           <array>
               <!-- 分页插件配置 -->
               <bean id="paginationInterceptor" class="com.baomidou.mybatisplus.plugins.PaginationInterceptor">
                   <property name="dialectType" value="mysql"/>
               </bean>
           </array>
       </property>
       <!-- 全局配置注入 -->
       <property name="globalConfig" ref="globalConfig" /> 
</bean>


<bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration">
        <!-- 
            AUTO->`0`("数据库ID自增")
             INPUT->`1`(用户输入ID")
            ID_WORKER->`2`("全局唯一ID")
            UUID->`3`("全局唯一ID")
        -->
        <property name="idType" value="2" />
        <!--
            MYSQL->`mysql`
            ORACLE->`oracle`
            DB2->`db2`
            H2->`h2`
            HSQL->`hsql`
            SQLITE->`sqlite`
            POSTGRE->`postgresql`
            SQLSERVER2005->`sqlserver2005`
            SQLSERVER->`sqlserver`
        -->
        <!-- Oracle需要添加该项 -->
        <!-- <property name="dbType" value="oracle" /> -->
        <!-- 全局表为下划线命名设置 true -->
        <property name="dbColumnUnderline" value="true" />

    </bean>

<!-- 热加载 目的是调试方便 -->
<bean class="com.baomidou.mybatisplus.spring.MybatisMapperRefresh">
    <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
    <constructor-arg name="mapperLocations" value="classpath:com/vv/mapping/*.xml"/>
    <constructor-arg name="delaySeconds" value="5"/>
    <constructor-arg name="sleepSeconds" value="10"/>
    <constructor-arg name="enabled" value="true"/>
</bean>


<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.vv.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

<!--注解方式:添加事务处理
<tx:annotation-driven transaction-manager="txManager" />
-->
<!--添加事务处理-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbcDataSource" />
</bean>

</beans>



除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: python安装教程

下一篇: Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 8.x

精华推荐