文章目录
项目结构generateConfig.xmlpom.xml使用git地址下载
目前接触到的比较好的基于mybatis的操作数据库的有两种一种是pagehelper带分页,一种是mybatis-plus。
现在记录下用到pagehelper。
这个项目直接作为moudle引入模块即可。
项目结构
generateConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry
location="D:\soft\apache-maven-3.3.9\maven_home\mysql\mysql-connector-java\5.1.45\mysql-connector-java-5.1.45.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/pinyougoudb?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&allowMultiQueries=true"
userId="root"
password="123456"/>
<javaModelGenerator targetPackage="com.pinyougou.pojo"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.pinyougou.mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.pinyougou.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table schema="" tableName="tb_address"></table>
<table schema="" tableName="tb_areas"></table>
<table schema="" tableName="tb_brand"></table>
<table schema="" tableName="tb_cities"></table>
<table schema="" tableName="tb_content"></table>
<table schema="" tableName="tb_content_category"></table>
<table schema="" tableName="tb_freight_template"></table>
<table schema="" tableName="tb_goods"></table>
<table schema="" tableName="tb_goods_desc"></table>
<table schema="" tableName="tb_item"></table>
<table schema="" tableName="tb_item_cat"></table>
<table schema="" tableName="tb_order"></table>
<table schema="" tableName="tb_order_item"></table>
<table schema="" tableName="tb_pay_log"></table>
<table schema="" tableName="tb_provinces"></table>
<table schema="" tableName="tb_seckill_goods"></table>
<table schema="" tableName="tb_seckill_order"></table>
<table schema="" tableName="tb_seller"></table>
<table schema="" tableName="tb_specification"></table>
<table schema="" tableName="tb_specification_option"></table>
<table schema="" tableName="tb_type_template"></table>
<table schema="" tableName="tb_user"></table>
</context>
</generatorConfiguration>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pinyougou-parent
</artifactId>
<groupId>com.pinyougou
</groupId>
<version>1.0-SNAPSHOT
</version>
</parent>
<modelVersion>4.0.0
</modelVersion>
<artifactId>pingyougou-generate
</artifactId>
<dependencies>
<dependency>
<groupId>org.mybatis.generator
</groupId>
<artifactId>mybatis-generator-core
</artifactId>
<version>1.3.5
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator
</groupId>
<artifactId>mybatis-generator-maven-plugin
</artifactId>
<version>1.3.2
</version>
<configuration>
<configurationFile>src/main/resources/mybatis/generatorConfig.xml
</configurationFile>
<verbose>true
</verbose>
<overwrite>true
</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts
</id>
<goals>
<goal>generate
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
使用
双击下面的插件即可。
git地址下载
https://github.com/hufanglei/pagehelper-generate.git
完