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、点击脚本文件在该价夹中将会看到生成的文件
点击后
小白技术分享
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· 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