MyBatis逆向工程的使用
来源:互联网 发布:李奥瑞克的王冠数据 编辑:程序博客网 时间:2024/06/04 23:20
通过cmd命令行生成
1.配置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="E:/workspace/unifiedWaiMaiPlatform/WebRoot/WEB-INF/lib/mysql-connector-java-5.1.32.jar"/> <context id="my" targetRuntime="MyBatis3"> <plugin type="org.alex.mybatis.common.plugin.PaginationPlugin"/> <commentGenerator> <property name="suppressDate" value="false"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--配置数据库连接信息 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://drds0c163972v37tpublic.drds.aliyuncs.com:3306/business" userId="business" password="dev_55567707"/> <!--生成实体对象的位置以及项目的位置--> <javaModelGenerator targetPackage="org.hshk.demo.orm.entity" targetProject="E:\workspace\unifiedWaiMaiPlatform\src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成Mapper映射XML文件位置以及所在项目的位置 --> <sqlMapGenerator targetPackage="org.hshk.demo.orm.mapper" targetProject="E:\workspace\unifiedWaiMaiPlatform\src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成Mapper接口文件位置以及所在项目的位置 --> <javaClientGenerator targetPackage="org.hshk.demo.orm.mapper" targetProject="E:\workspace\unifiedWaiMaiPlatform\src" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成哪些表(更改tableName和domainObjectName就可以) --> <!-- tableName:要生成的表名 ; domainObjectName:生成后的实例名 enableCountByExample:Count语句中加入where条件查询,默认为true开启 enableUpdateByExample:Update语句中加入where条件查询,默认为true开启 enableDeleteByExample:Delete语句中加入where条件查询,默认为true开启 enableSelectByExample:Select多条语句中加入where条件查询,默认为true开启 selectByExampleQueryId:Select单个对象语句中加入where条件查询,默认为true开启 --> <!--检查好需要生成的表名--> <table tableName="saas_order" domainObjectName="SaasOrder" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" alias="CouponOrder"> </table> <table tableName="saas_food" domainObjectName="SaasFood" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" alias="CouponOrderMenu"> </table> <table tableName="saas_bill" domainObjectName="saas_bill" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" alias="CouponRestaurant"> </table> </context></generatorConfiguration>
2.CMD中的命令
java -jar ./WebRoot/WEB-INF/lib/mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml
mybatis-generator-core-1.3.2.jar 是mybatis逆向工程的核心jar包;
./WebRoot/WEB-INF/lib/mybatis-generator-core-1.3.2.jar 是在需要生成的项目目录下, 若jar包在其他位置自己进行路径的配置;
-configfile generatorConfig.xml 加载配置文件;
cmd中输入上面的命令,敲击回车后
***E:\workspace\unifiedWaiMaiPlatform>java -jar ./WebRoot/WEB-INF/lib/mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml
MyBatis Generator finished successfully.
E:\workspace\unifiedWaiMaiPlatform>pause
请按任意键继续…*
cmd中出现上面的命令代表生成成功,若生成失败检查下自己的配置文件以及cmd命令;
如果逆向工程多次使用的话,可以将cmd命令生成为一个 .bat文件,windows下双击直接就会运行cmd命令;
3.生成完成
生成后的文件
其中,Example文件用于添加条件,相当于sql中where后的部分’
mapper.xml中生成的CRUD,可以满足基本的需求;
查询时,只要熟练运用 xxxExample文件,基本可以满足所有的查询需求
阅读全文
0 0
- mybatis逆向工程的使用
- MyBatis逆向工程的使用
- MyBatis逆向工程的使用
- Mybatis逆向工程的使用
- 【mybatis】mybatis的逆向工程使用步骤
- mybatis的逆向工程使用实现
- Mybatis的逆向工程如何使用
- mybatis逆向工程的创建和使用
- mybatis 的逆向工程
- mybatis的逆向工程
- mybatis的逆向工程
- mybatis的逆向工程
- Mybatis的逆向工程
- MyBatis 的逆向工程
- mybatis的逆向工程
- mybatis的逆向工程
- mybatis的逆向工程
- mybatis 的逆向工程
- JeeSite代码生成功能的使用(记录)
- httpclient connecttimeout sockettimeout区别
- 消息队列的应用场景以及优缺点
- 【wxPython】wxPython显示鼠标位置
- JAVA语言学习开始
- MyBatis逆向工程的使用
- ajax传递数据
- Python Windows下操作文件夹和文件
- Google DeepMind顾问预言:五年后AI将在《星际争霸》中战胜人类
- 栈
- uboot的sd/mmc流程
- 笔记:mysql查看表的结构及注释、创建表sql语句方法。
- spring类图二 DefaultListableBeanFactory相关类图
- webkit介绍