您的位置 首页 java

懂了Java逆向工程,你还害怕一个人接项目?

场景: 开发中为了节约资源,提高效率,往往采用敏捷开发,因此,在搭建一个项目的时候, 逆向工程 的必不可少的。


知识点: 使用逆向工程,首先得安装 maven ,否则无法实现(maven不会安装的,请私信),初次之外,还需要 mybatis 和mysql的jar包。逆向工程有两种方式,一种是命令行执行,一种是通过 idea 的操作(其实也是命令行操作)

方式一

1、目录结构

需要的mybatis和mysql包

2、逆向工程配置文件generatorConfig.xml内容

 <?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE generator configuration   
  PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
  "#34;>  
<generatorConfiguration>  
<!-- 数据库驱动-->  
    <classPathEntry  location="mysql-connector- Java -5.1.30.jar"/>  
    <context id="DB2Tables"  targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressDate" value="true"/>  
            <!-- 是否去除自动生成的注释 true:是 :  false :否 -->  
            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  
        <!--数据库链接URL,用户名、密码 -->  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/test1" userId="root" password="yang156122">  
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
        <!-- 生成模型的包名和位置-->  
        <javaModelGenerator targetPackage="test.model" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  
        <!-- 生成映射文件的包名和位置-->  
        <sqlMapGenerator targetPackage="test.mapping" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  
        <!-- 生成 dao 的包名和位置-->  
        <javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="src">  
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>  
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->  
        <table tableName="syspermission" domainObjectName="Syspermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        
        <table tableName="sysrole" domainObjectName="Sysrole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

        <table tableName="user_t" domainObjectName="User_t" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>  
</generatorConfiguration>  

3、进入到步骤1中的目录中,执行下面命令

 java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite  

方式二

1、重申:maven需要先配置。首先建立一个springboot工程,在 pom .xml中添加以下配置

 <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>
  </plugin>  

2、generatorConfig.xml内容,注意,targetPackage是包名,targetProject是路径名,数据库驱动是本地的mysql数据连接驱动。(这部分和方式一的配置文件一致)

3、idea中使用maven命令执行

maven命令

如果需要mybatis和mysql的jar包,请转发+关注,然后私信我。

感谢转发+专注!!为劳动人民点赞吧!

文章来源:智云一二三科技

文章标题:懂了Java逆向工程,你还害怕一个人接项目?

文章地址:https://www.zhihuclub.com/200995.shtml

关于作者: 智云科技

热门文章

网站地图