吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4526|回复: 14
收起左侧

[Java 转载] Mybatis 逆向工程配置及实现

  [复制链接]
chg122345 发表于 2018-7-25 10:48
  • 创建配置文件

   ---在类路径下创建generatorConfig.xml,内容如下:
  
[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="/home/local/mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar"/>
    <context id="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/mall" userId="root" password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="org.jleopard.mall.model" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
                type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
                type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
                type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
        -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="org.jleopard.mall.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
        <table tableName="ml_user"  domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="ml_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="ml_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="ml_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="ml_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="ml_address" domainObjectName="Address" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

    </context>
</generatorConfiguration>

  2. 配置maven插件运行
[XML] 纯文本查看 复制代码
 
<build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
        </plugins>
    </build>

  3. 编辑运行代码,运行即可
Screenshot from 2018-07-25 10-45-14.png
4. 运行结果

Screenshot from 2018-07-25 10-47-15.png
Screenshot from 2018-07-25 10-47-31.png

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
fdkn1984 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Rukawalee 发表于 2020-1-7 09:13
beibeibei 发表于 2019-4-13 16:13
楼主我遇到一个问题
比如我要插入一个学生的数据
        students students=new students();

不知道层主是否解决?那是因为,sqlSession设置了autoCommit(false),所以层主需要手动提交或者openSession(true)即可
benbenxiong 发表于 2018-7-25 11:27
checkz 发表于 2018-7-25 11:32
 楼主| chg122345 发表于 2018-7-28 08:10
benbenxiong 发表于 2018-7-25 11:27
生成了实体map xml 内容呢? 基本的增删改查 吗

自动生成的只有单表操作,关联查询,分步查询还是要自己写的
torboxin 发表于 2018-7-28 11:24
大学生毕业前都是C贴,现在java贴开始变多了
流星的孤单 发表于 2018-7-29 16:08
嗯嗯不错,值得学习
panjun 发表于 2018-7-30 13:41
受教了,新手还在学习中
金龙影子 发表于 2018-7-30 15:27
楼主辛苦了!
云驿站 发表于 2018-8-10 09:43
这个可以叫逆向工程吗
流星的孤单 发表于 2018-8-10 09:45
楼主辛苦了!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 08:08

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表