菜鸟一枚,记录成长(2)
发布日期:2021-09-11 14:30:24 浏览次数:39 分类:技术文章

本文共 3775 字,大约阅读时间需要 12 分钟。

hot3.png

  1. 首先下载generate工具 主要就是jar包和xml文件(自己写太难了)提取码:srvk
  2. 然后编写generator配置文件 需要注意的地方已经注释上去了,只要修改下配置文件就ok了。

<?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\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\mysql-connector-java-5.1.26-bin.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/sy" userId="root" password="123456">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
        <javaModelGenerator targetPackage="cn.lsu.model" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- 生成的映射文件包名和位置 -->
        <sqlMapGenerator targetPackage="cn.lsu.mapping" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="cn.lsu.dao" targetProject="C:\Users\Gost\Desktop\SpringMvc+Spring+MyBatis+Maven\generator\generator\src">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
        <table tableName="tuser" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="tmenu" domainObjectName="Menu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="tonline" domainObjectName="Online" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="tresource" domainObjectName="Resource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="trole" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="tbug" domainObjectName="Bug" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="trole_tresource" domainObjectName="RoleResource" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
        <table tableName="tuser_trole" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    </context>
</generatorConfiguration>

3.然后建立空的src文件夹

4.shift+右键在此位置运行(xp没有此功能,只有在cmd中依次找到文件)执行语句

java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite(在执行语句时注意你上面配置的一切路径不要有中文,还有就是可能遇到总是报“前言中不允许有内容”的问题,解决方案:

用记事本打开xml文件转化为UTF-8会有一个BOM头,所以java在读取时就会报以上错误

解决方法:用notepad++打开,在格式选择“以UTF-8无BOM格式编码”,然后保存, 就可以了

完成代码的自动生成

 

本人以为generate工具大大提高了开发效率希望对大家有益

 

 

 

转载于:https://my.oschina.net/yuzhoukai/blog/704439

转载地址:https://blog.csdn.net/weixin_34413802/article/details/92435823 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:会员信息录入时,性别项应该怎么填写最合理呢?
下一篇:sh脚本中变量$的坑

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月30日 19时55分37秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

【C++】算法集锦(10)通俗讲kmp算法 2019-04-27
【C++】算法集锦(12):高楼扔鸡蛋 2019-04-27
【图解】拥塞控制 2019-04-27
线程上下文切换 2019-04-27
什么是服务熔断? 2019-04-27
服务器压力过大?CPU打满?我来帮你快速检查Linux服务器性能 2019-04-27
C++面经总结之《Effective C++》(一) 2019-04-27
C++面经总结之《Effective C++》(二) 2019-04-27
这是什么“虎狼之词”啊!!!程序员的健康问题,看一线老中医怎么说!!! 2019-04-27
打开我的收藏夹 -- Python数据分析杂谈 2019-04-27
上手Pandas,带你玩转数据(1)-- 实例详解pandas数据结构 2019-04-27
上手Pandas,带你玩转数据(2)-- 使用pandas从多种文件中读取数据 2019-04-27
上手Pandas,带你玩转数据(3)-- pandas数据存入文件 2019-04-27
爬虫遇上不让右击、不让F12的网站,该怎么办? 2019-04-27
上手Pandas,带你玩转数据(4)-- 数据清洗 2019-04-27
上手Pandas,带你玩转数据(5)-- 数据转换与数据定位 2019-04-27
上手Pandas,带你玩转数据(6)-- 摆脱对pandas可视化丑图的刻板印象吧 2019-04-27
从零开始,学会Python爬虫不再难!!! -- (1)开篇:初识爬虫,基础铺垫 丨蓄力计划 2019-04-27
从零开始,学会Python爬虫不再难!!! -- (2)承接:解析网页,抓取标签 丨蓄力计划 2019-04-27
AttributeError: module ‘urllib‘ has no attribute ‘quote‘的解决办法 2019-04-27