http://blog.csdn.net/google_webmaster/article/details/72996887
特点,idea安装好这个插件之后,可以在dao层的方法中直接跳转到mapper中,十分方便,还有排错的功能。
直接搜索这个插件安装就行。
只需要在数据库建好表,在generatorConfig.xml中配置就行了。
需要在pom中添加以下依赖
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.3.2version>
<scope>testscope>
dependency>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.2version>
<configuration>
<verbose>trueverbose>
<overwrite>trueoverwrite>
configuration>
plugin>
generatorConfig.xml
<generatorConfiguration>
<classPathEntry
location="G:\tool\apache-maven-3.5.2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />
<context id="MysqlTables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mama-bike"
userId="root" password="root">
jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
javaTypeResolver>
<javaModelGenerator targetPackage="com.coder520.mamabike.fee.entity"
targetProject="G:\IDEAworkspace\mama-bike\src\main\java"
>
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
javaModelGenerator>
<sqlMapGenerator targetPackage="com.coder520.mamabike.fee.dao"
targetProject="G:\IDEAworkspace\mama-bike\src\main\java">
<property name="enableSubPackages" value="true" />
sqlMapGenerator>
<javaClientGenerator targetPackage="mappers"
targetProject="./src/main/resources"
type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
javaClientGenerator>
<table tableName="ride_fee" domainObjectName="RideFee"
enableInsert="true" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
table>
context>
generatorConfiguration>
pom
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelperartifactId>
<version>4.1.0version>
dependency>
<dependency>
<groupId>com.github.miemiedevgroupId>
<artifactId>mybatis-paginatorartifactId>
<version>1.2.17version>
dependency>
<dependency>
<groupId>com.github.jsqlparsergroupId>
<artifactId>jsqlparserartifactId>
<version>0.9.4version>
dependency>
然后需要在spring的配置文件中配置一下。具体是需要在datasource中配置需要加一个
,这里就直接把全部的xml贴进来了
applicationContext-datasource.xml
<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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="com.mmall" annotation-config="true"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="2"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:datasource.propertiesvalue>
list>
property>
<property name="fileEncoding" value="utf-8"/>
bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="initialSize" value="${db.initialSize}"/>
<property name="maxActive" value="${db.maxActive}"/>
<property name="maxIdle" value="${db.maxIdle}"/>
<property name="minIdle" value="${db.minIdle}"/>
<property name="maxWait" value="${db.maxWait}"/>
<property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/>
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/>
<property name="timeBetweenEvictionRunsMillis" value="40000"/>
<property name="testWhileIdle" value="true"/>
<property name="validationQuery" value="SELECT 1 FROM dual"/>
bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mappers/*Mapper.xml">property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
value>
property>
bean>
array>
property>
bean>
<bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mmall.dao"/>
bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="rollbackOnCommitFailure" value="true"/>
bean>
beans>