java中entity和dao层生成之逆向工具

1、创建一个generator文件夹方便存放需要的jar包、配置文件、脚本文件和生成的文件

2、下载mybatis和mysql(根据自己数据库来下载)依赖的jar包放到创建好的文件夹下

 

 

 3、在文件夹中创建和文件夹名相同的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="F:\generator\postgresql-9.4.1212.jre7.jar" />
    <!--<classPathEntry location="D:\generator\mysql-connector-java-5.1.13.jar" />-->
    <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" /> -->
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!-- 数据库链接URL、用户名、密码 -->
        <jdbcConnection driverClass="org.postgresql.Driver" connectionURL="jdbc:postgresql://localhost/demo" userId="postgres" password="123456">
        <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/exam" userId="root" password="123456">-->
        <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa"> -->
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator targetPackage="com.demo.entity" targetProject="F:\generator\src">
            <property name="enableSubPackages" value="false" />
            <property name="trimStrings" value="true" /> 
        </javaModelGenerator>
        <!-- 生成的映射文件包名和位置 -->
        <sqlMapGenerator targetPackage="com.demo.mapper" targetProject="F:\generator\src">
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>
        <!-- 生成mapper接口的包名和位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.dao" targetProject="F:\generator\src">
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        
        <!-- 要生成那些表(更改tableName和domainObjectName就可以) enable参数的值为true时生成的内容更具体,大家可以上网了解-->
        <table tableName="demo2" enableCountByExample="false" enableUpdateByExample="false" 
            enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    
        <!--<table tableName="apply_register_info" enableCountByExample="false" enableUpdateByExample="false" 
            enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />-->
        <!--
        <table tableName="orders"/>
        <table tableName="orderdetail"/>
        <table tableName="user"/>
        -->
        <!--
        <table tableName="station" domainObjectName="Station" enableCountByExample="false" enableUpdateByExample="false" 
            enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        -->
    </context>
</generatorConfiguration>
复制代码

4、在文件夹中创建生成语句的文本文件,文件中加入下列语句(可以省略)

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

5、在文件夹中创建执行脚本文件(.bat)

@echo off
F:
::必须是你创建的文件夹位置
cd F:\generator
::生成语句
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

6、点击脚本文件在该价夹中将会看到生成的文件

 

 点击后

 

posted @   过氧化氢  阅读(529)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示