Skip to content

Commit

Permalink
更新通用Mapper3.1.3-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed Jul 14, 2015
1 parent c970885 commit d54ed9c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 78 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.isea533</groupId>
Expand All @@ -22,8 +22,8 @@
<!-- 编译jdk版本 -->
<jdk.version>1.6</jdk.version>
<!-- 依赖版本 -->
<mapper.version>3.1.0</mapper.version>
<pagehelper.version>3.7.4</pagehelper.version>
<mapper.version>3.1.3-SNAPSHOT</mapper.version>
<pagehelper.version>4.0.0</pagehelper.version>
<mysql.version>5.1.29</mysql.version>
<spring.version>4.1.2.RELEASE</spring.version>
</properties>
Expand Down Expand Up @@ -171,7 +171,7 @@
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
</dependency>
<!-- Mybatis Generator -->
<dependency>
Expand Down
147 changes: 74 additions & 73 deletions src/main/resources/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
~ THE SOFTWARE.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
Expand All @@ -37,88 +37,89 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.isea533.mybatis.service"/>
<context:component-scan base-package="com.isea533.mybatis.service"/>

<context:property-placeholder location="classpath:config.properties"/>
<context:property-placeholder location="classpath:config.properties"/>

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClass}"/>
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}" />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClass}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>

<property name="filters" value="stat" />
<property name="filters" value="stat"/>

<property name="maxActive" value="20"/>
<property name="initialSize" value="1"/>
<property name="maxWait" value="60000"/>
<property name="minIdle" value="1"/>
<property name="maxActive" value="20"/>
<property name="initialSize" value="1"/>
<property name="maxWait" value="60000"/>
<property name="minIdle" value="1"/>

<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<property name="minEvictableIdleTimeMillis" value="300000"/>

<property name="validationQuery" value="SELECT 'x'"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
</bean>
<property name="validationQuery" value="SELECT 'x'"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations">
<array>
<value>classpath:mapper/*.xml</value>
</array>
</property>
<property name="typeAliasesPackage" value="com.isea533.mybatis.model"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
reasonable=true
</value>
</property>
</bean>
<bean class="tk.mybatis.mapper.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=tk.mybatis.mapper.common.Mapper
IDENTITY=MYSQL
notEmpty=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations">
<array>
<value>classpath:mapper/*.xml</value>
</array>
</property>
<property name="typeAliasesPackage" value="com.isea533.mybatis.model"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
reasonable=true
</value>
</property>
</bean>
<bean class="tk.mybatis.mapper.mapperhelper.MapperOnceInterceptor">
<property name="properties">
<value>
mappers=tk.mybatis.mapper.common.Mapper
IDENTITY=MYSQL
notEmpty=true
</value>
</property>
</bean>
</array>
</property>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.isea533.mybatis.mapper"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="addToConfig" value="true"/>
<property name="basePackage" value="com.isea533.mybatis.mapper"/>
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean>

<aop:aspectj-autoproxy/>
<aop:aspectj-autoproxy/>

<aop:config>
<aop:pointcut id="appService" expression="execution(* com.isea533.mybatis.service..*Service*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="appService"/>
</aop:config>
<aop:config>
<aop:pointcut id="appService" expression="execution(* com.isea533.mybatis.service..*Service*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="appService"/>
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="select*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="select*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
6 changes: 5 additions & 1 deletion src/test/java/com/isea533/mybatis/test/PageMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

package com.isea533.mybatis.test;

import tk.mybatis.mapper.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.isea533.mybatis.mapper.CountryMapper;
import com.isea533.mybatis.model.Country;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

Expand All @@ -50,5 +50,9 @@ public void test(){
List<Country> countries = countryMapper.selectByExample(example);
PageInfo<Country> pageInfo = new PageInfo<Country>(countries);
System.out.println(pageInfo.getTotal());

countries = countryMapper.selectByExample(example);
pageInfo = new PageInfo<Country>(countries);
System.out.println(pageInfo.getTotal());
}
}

0 comments on commit d54ed9c

Please sign in to comment.