mybatis XML开发 插件一键生成配置
pom文件:
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7-SNAPSHOT</version>
</dependency>
在根目录建立文件夹conf
里面新建conf文件
<?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>
<!-- 中文文档::::::::::http://mbg.cndocs.ml/index.html -->
<!--context 属性说明
defaultModelType:指定生成对象的样式
1,conditional:类似hierarchical;
2,flat:所有内容(主键,blob)等全部生成在一个对象中;
3,hierarchical:主键生成一个XXKey对象(key class),Blob等单独生成一个对象,其他简单属性在一个对象中(record class)
targetRuntime:
1,MyBatis3:默认的值,生成基于MyBatis3.x以上版本的内容,包括XXXBySample;
2,MyBatis3Simple:类似MyBatis3,只是不生成XXXBySample;
-->
<context id="MybatisGenerator" defaultModelType="flat" targetRuntime="MyBatis3">
<property name="autoDelimitKeywords" value="true"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!--为生成的Java模型创建一个toString方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<commentGenerator>
<!-- 是否去除自动生成的注释,默认 false-->
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://xxxxxx"
userId="xxxx"
password="xxxxxxx">
</jdbcConnection>
<javaTypeResolver>
<!-- This property is used to specify whether MyBatis Generator should force the use of JSR-310 data types for DATE, TIME,
and TIMESTAMP fields, rather than using java.util.Date -->
<property name="useJSR310Types" value="false"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="com.kuaishou.is.pm.presentation.domain"
targetProject="src/main/java">
<!-- enableSubPackages:在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"/>
<!--specify target package and target project for generated client interfaces and classes-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.xxxxx"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--<table tableName="pm_team" domainObjectName="Team">-->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--</table>-->
<!-- <table tableName="pm_task_type" domainObjectName="NewTaskType">-->
<!-- <generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!-- <columnOverride column="title" jdbcType="VARCHAR" />-->
<!-- </table>-->
<!--<table tableName="todo_remind_record" domainObjectName="ToDoRemindRecord">-->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!-- <table tableName="pm_comment" domainObjectName="Comment">-->
<!--<table tableName="pm_team" domainObjectName="Team">-->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--</table>-->
<!-- <table tableName="lab_user_module" domainObjectName="LabUserModule">-->
<!-- <generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!-- </table>-->
<table tableName="task_status_config" domainObjectName="TaskStatusConfig">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
<!--<table tableName="目标表名" domainObjectName="dominName">-->
<!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--</table>-->
</context>
</generatorConfiguration>
根据你的表名,想生成的xml 和mapper 放哪,自定义conf
然后
点击插件一键生成代码