根据数据库表结构生成Java的po类
pom文件配置
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-generator</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.dongfg.plugin</groupId>
<artifactId>mybatis-generator-lombok-plugin</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
generatorConfig.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>
<!-- 引入配置文件 -->
<!-- 一个数据库一个context -->
<context id="Oracle" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 生成的pojo,将implements Serializable -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<!-- 简化实体类 启用lombok@Data注解 -->
<plugin type="com.github.dongfg.plugin.LombokPlugin">
<property name="hasLombok" value="true"/>
</plugin>
<!-- 生成的mapper默认实现指定接口 -->
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.baomidou.mybatisplus.core.mapper.BaseMapper"/>
</plugin>
<!-- 注释 -->
<commentGenerator>
<property name="addRemarkComments" value="true"/>
<property name="suppressAllComments" value="false"/><!-- 是否取消注释 -->
<property name="suppressDate" value="true"/> <!-- 是否生成注释代时间戳-->
<property name="javaFileEncoding" value="UTF-8"/>
</commentGenerator>
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@172.0.0.0:1521:DATABASE"
userId="root"
password="root">
<property name="remarksReporting" value="true"/>
</jdbcConnection>
<!-- 生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java,
也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下 -->
<javaModelGenerator targetPackage="com.baidu.entity" targetProject="src/main/java"/>
<!--对应的mapper.xml文件-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" />
<!-- <!–对应的Mapper接口类文件–> -->
<javaClientGenerator targetPackage="com.baidu.dao" targetProject="src/main/java"
type="XMLMAPPER"/>
<!--列出要生成代码的所有表,这里配置的是不生成Example文件 -->
<table tableName="KAPP_JIEJRB" domainObjectName="KappJiejrb" />
<!-- <generatedKey column="id" sqlStatement="Oracle" identity="true"/>-->
</context>
</generatorConfiguration>
使用
双击运行【mybatis-generator:generate】即可