IntelliJ IDEA(2019)之mybatis反向生成的实现
2019-10-14 18:07
465 查看
mybatis的逆向工程是非常便捷的操作,能够显著的提高我们的开发效率,之前介绍过Eclipse的操作,本文来介绍下在idea中怎么处理。
mybatis逆向工程
1.配置文件
在resources目录下创建配置文件,具体如下:
<?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="C:\Users\dengp\.m2\repository\mysql\mysql-connector-java\5.1.27\mysql-connector-java-5.1.27.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 去掉生成文件中的注释 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dpb-srm" userId="root" password="123456"> </jdbcConnection> <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:XE" userId="car" password="car"> </jdbcConnection> --> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 当前项目下 .\--> <javaModelGenerator targetPackage="com.sxt.sys.pojo" targetProject=".\src\main\java"> <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.sxt.sys.mapper" targetProject=".\src\main\java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table tableName="t_emp" domainObjectName="Emp" schema=""></table> <table tableName="t_basic" domainObjectName="Basic" schema=""></table> <table tableName="t_dept" domainObjectName="Dept" schema=""></table> <table tableName="t_role" domainObjectName="Role" schema=""></table> <table tableName="t_user" domainObjectName="User" schema=""></table> <table tableName="t_menu" domainObjectName="Menu" schema=""></table> </context> </generatorConfiguration>
2.插件依赖
在pom.xml文件中添加mybatis的generator插件。具体如下:
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <!--关联上面的配置文件 --> <configurationFile>src/main/resources/mybatis-generator/generatorConfig-sys.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin>
3.反向生成
生成的方式有多种,我们此处介绍一种简便常用的方式,直接通过idea的plugin方式生成,如图。
生成成功
最后生成好后将插件注释掉即可
好了~搞定。以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- MyBatis自动生成Java/C#的Bean(Entity)的等价MYSQL实现函数
- Intellij IDEA 2016学习系列之(三)修改mybatis-generator源码生成中文注释
- MyEclipse下安装MyBatis Generator代码反向生成工具
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)
- mybatis反向生成实体类、dao层以及映射文件
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- 使用Myeclipse10.0自动生成搭建SSH框架(数据库表自动反向转换成Hibernate实体)实现用户登陆
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- mybatis-generator(mybatis根据已创建表反向生成对应的实体类、mapper文件和mapper.xml文件)
- Mybatis如何根据mapper接口生成其实现类
- Intellij Idea 中hibernate 反向生成实体
- MyBatis Generator (MBG),如何实现生成的代码,对应的类和 mapper 文件保持与对应的表名大小写不变
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- mybatis如何根据mapper接口生成其实现类
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- Intellij IDEA 中使用 MyBatis-generator 自动生成 MyBatis 代码
- mybatis如何根据mapper接口生成其实现类