我相信现在大多数公司java已经在使用idea 作为开发 工具了. 虽然idea 有版权, 需要破解, 购买正版等等, 但是其开发体验, 开发功能,开发速度, 热部署等等优点还是深受大众的喜爱啊, 从前年开始就一直用idea了, 中间一些操作, 现在慢慢写博客, 做记录. 还是补补吧. 好记性不如烂笔头, 今年上半年的flag 还要把收藏夹里收藏的好的博客, 文章,知识点等等都整理整理回顾回顾 写写博客, 记录下来.. 主要是碎片化时间弄.
创建一个maven工程
不会的朋友可以去看看我的这篇博客 使用IDEA创建maven项目 .
配置pom文件
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency> <dependency> <groupId>com.itfsw</groupId> <artifactId>mybatis-generator-plugin</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin>
在src/main/resources 新建文件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> <classPathEntry location="D:Repositorymysqlmysql-connector-java5.1.40mysql-connector-java-5.1.40.jar" /> <context id="infoGuardian" targetRuntime="MyBatis3"> <!-- 注释 --> <commentGenerator> <property name="suppressAllComments" value="true" /><!-- 是否取消注释 --> <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 --> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/xxx?serverTimezone=Hongkong" userId="root" password="xxx"> </jdbcConnection> <!-- 只有一个属于forceBigDecimals,默认false。 如果字段精确超过0,生成BigDecimal 如果字段精确是0,总长度10-18生成Long;如果字段精确是0, 总长5-9生成Integer; 如果字段精确是0,总长小于5生成Short; 如果forceBigDecimals为true,统一生成BigDecimal --> <javaTypeResolver> <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成vo、model --> <javaModelGenerator targetPackage="com.spSystem.model" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> <!-- 是否针对string类型的字段在set的时候进行trim调用 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成mapxml文件 --> <sqlMapGenerator targetPackage="com.spSystem.model" targetProject="src/main/java" /> <!-- 生成mapxml对应client,也就是接口dao --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.spSystem.model" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- <table tableName="xxx" domainObjectName="xxx" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"> </table>--> </context> </generatorConfiguration>
点击 菜单run中Edit Configurations-> 点击+号,选择maven,输入命令
mybatis-generator:generate -e