文章目录
1mybaits三剑客
开发生成器:连接数据库—》获取表结构—》生成文件
2mybatis-genertor;
2.1引入依赖
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
2.2在resource下建立generatorConfig.xml
对应的解释说明:
Mybatis Generator 配置详解
https://www.imooc.com/article/21444
<?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>
<!-- 1 windows下路径, D:\downloads\xxx.jar-->
<classPathEntry location="/Users/admin/Desktop/mysql-connector-java-5.1.6.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 不再追加xml内容-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- 不生成注释-->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 2 修改链接地址,用户名和密码-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8"
userId="root"
password="123456">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 3 实体类位置,-->
<javaModelGenerator targetPackage="com.imooc.mall.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<!-- <property name="trimStrings" value="true" />-->
</javaModelGenerator>
<!-- 4 mapper位置,-->
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 5 dao位置,-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.imooc.mall.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- <table tableName="mall_order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!-- <table tableName="mall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!-- <table tableName="mall_user" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!-- <table tableName="mall_category" domainObjectName="Category" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!-- <table tableName="mall_product" domainObjectName="Product" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false">-->
<!-- <columnOverride column="detail" jdbcType="VARCHAR" />-->
<!-- <columnOverride column="sub_images" jdbcType="VARCHAR" />-->
<!-- </table>-->
<table tableName="mall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
</context>
</generatorConfiguration>
注意:
1方法上有很多注解
解决:
<!-- 不生成注释-->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
2 多生成一个orderExample 类
解决:
添加配置
enableCountByExample=“false” enableDeleteByExample=“false”
<table tableName="mall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
2.3运行:
3free-mybatis-plugin
mybatis-plugin. 收费。安装会报错,不建议安装
free-mybatis-plugin. 免费
3.1安装插件