逆向工程
注: 有数据库表即可 第一步为创建数据库表
- (可选)使用PowerDesigner设计数据库表,物理模型构建
- 添加pom.xml 逆向工程生成代码插件
<!--plugin 逆向工程生成代码插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!--重点:要自己改 你的配置文件位置 从src外层开始算 我的直接放在src同级目录 GeneratorMapper.xml的存放位置 -->
<configurationFile>GeneratorMapper.xml</configurationFile>
<!--可移动-->
<verbose>true</verbose>
<!--可覆盖-->
<overwrite>true</overwrite>
</configuration>
</plugin>
- 配置GeneratorMapper.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>
<!--要配置mysql驱动-->
<!--指定连接数据库的JDBC 驱动包所在位置,指定到你本机的完整路径-->
<classPathEntry location="D:\My_Apps\java_mavne\respository\mysql\mysql-connector-java\5.1.9\mysql-connector-java-5.1.9.jar"/>
<!--配置table表信息内容体,targetRuntime 指定采用MyBatis3的版本-->
<context id="tables" targetRuntime="MyBatis3">
<!--抑制生成注释,由于生成的注释都是英文的,可以不让它生成-->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--配置数据库连接信息-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mywork?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true"
userId="root"
password="123456">
<property name="nullCatalogMeansCurrent" value="true"/> </jdbcConnection> <!--生成model 类,targetPackage 指定 model 类的包名,targetProject 指定
生成的 实体类 model放在eclipse的哪个工程下面-->
<javaModelGenerator targetPackage="com.zhy.pojo"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="false"/>
</javaModelGenerator>
<!--生成 MyBatis的Mapper.xml文件,targetPackage 指定 mapper.xml文件的包名,targetProject 指定生成的 mapper.xml放在 eclipse的哪个工程下面
-->
<sqlMapGenerator targetPackage="mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator> <!--生成 MyBatis的 Mapper接口类文件,targetPackage 指定 Mapper 接口类的包名,targetProject 指定生成的 Mapper 接口放在eclipse 的哪个工程下面
-->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.zhy.dao"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator> <!--数据库表名及对应的Java模型类名-->
<table tableName="user" domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="apply" domainObjectName="Apply"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="article" domainObjectName="Article"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<!--
<table tableName="user" domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
-->
</context>
</generatorConfiguration>