• spring 整合 mybatis (不含物理分页)


    http://www.mybatis.org/spring/mappers.html 

    http://www.mybatis.org/spring/zh/mappers.html

    <?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:util="http://www.springframework.org/schema/util" 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/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    
        <util:properties id="db" location="classpath:db.properties"></util:properties>
        <context:annotation-config />
        <context:component-scan base-package="cn.zno" />
    
        <bean id="dataSourceTest" class="org.apache.commons.dbcp2.BasicDataSource"
            destroy-method="close">
            <property name="driverClassName" value="#{db['jdbc.driverClassName']}" />
            <property name="url" value="#{db['jdbc.url']}" />
            <property name="username" value="#{db['jdbc.username']}" />
            <property name="password" value="#{db['jdbc.password']}" />
            <property name="defaultAutoCommit" value="true" />
        </bean>
    
        <bean id="txManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSourceTest" />
        </bean>
    
        <tx:annotation-driven transaction-manager="txManager" />
    
        <!-- ================= -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSourceTest" />
            <property name="configLocation" value="classpath:mybatis-config.xml" />
        </bean>
    
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="cn.zno.dao" />
            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        </bean>
        
        <bean id="aService" class="cn.zno.service.AService"></bean>
        
    </beans>

    关于 basePackage

    第一,支持正则:

    如果 value 为 com.lzkj.zsl.clubber.server.entity.*.mapper

    会被解析成:classpath*:com/lzkj/zsl/clubber/server/entity/*/mapper/**/*.class

    Find all resources that match the given location pattern via the Ant-style PathMatcher. Supports resources in jar files and zip files and in the file system.

    org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources 

    第二,支持字符串数组:

    String CONFIG_LOCATION_DELIMITERS = ",; ";

    org.springframework.util.StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)

    举例:

    value="com.xx,com.yy"

    value="com.xx;com.yy;"

    value="com.*.mapper"

  • 相关阅读:
    struts2中拦截器与过滤器之间的区别
    使用struts2中默认的拦截器以及自定义拦截器
    图解Tomcat类加载机制
    Eclipse项目中引用第三方jar包时将项目打包成jar文件的两种方式
    SQL中的四种连接方式
    My97datepicker日期控件
    Java中如何判断一个日期字符串是否是指定的格式
    jxl导入/导出excel
    优化myeclipse启动速度以及解决内存不足问题
    170726、常用 Git 命令清单
  • 原文地址:https://www.cnblogs.com/zno2/p/4785330.html
Copyright © 2020-2023  润新知