zoukankan      html  css  js  c++  java
  • MyBatis-逆向工程

    MyBatis Generator:
    简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的根据表生成对应的映射文件,接口,以及bean类。支持基本的增删改查,以及QBC风格的条件查询。但是表连接、存储过程等这些复杂sql的定义需要我们手工编写
    官方文档地址
    http://www.mybatis.org/generator/
    官方工程地址
    https://github.com/mybatis/generator/releases

    使用步骤:
    1)编写MBG的配置文件(重要几处配置)
    1)jdbcConnection配置数据库连接信息
    2)javaModelGenerator配置javaBean的生成策略
    3)sqlMapGenerator 配置sql映射文件生成策略
    4)javaClientGenerator配置Mapper接口的生成策略
    5)table 配置要逆向解析的数据表
    tableName:表名
    domainObjectName:对应的javaBean名
    2)运行代码生成器生成代码
    注意:
    Context标签
    targetRuntime=“MyBatis3“可以生成带条件的增删改查
    targetRuntime=“MyBatis3Simple“可以生成基本的增删改查
    如果再次生成,建议将之前生成的数据删除,避免xml向后追加内容出现的问题。

    <generatorConfiguration>
      <context id="DB2Tables" targetRuntime="MyBatis3">
         //数据库连接信息配置
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost:3306/bookstore0629"
            userId="root" password="123456">
        </jdbcConnection>   
        //javaBean的生成策略
        <javaModelGenerator targetPackage="com.atguigu.bean"  targetProject=".src">
          <property name="enableSubPackages" value="true" />
          <property name="trimStrings" value="true" />
        </javaModelGenerator>
        //映射文件的生成策略
        <sqlMapGenerator targetPackage="mybatis.mapper"   targetProject=".conf">
          <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        //dao接口java文件的生成策略
        <javaClientGenerator type="XMLMAPPER"  targetPackage="com.atguigu.dao"  
          targetProject=".src">
          <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        //数据表与javaBean的映射
        <table tableName="books" domainObjectName="Book"></table>
      </context>
    </generatorConfiguration>
  • 相关阅读:
    连载:面向对象葵花宝典:思想、技巧与实践(2)
    关于虚拟化一些思考——不应该盲目使用
    Zimbra8.x邮件服务器安装及配置
    CodeForces 371D. Vessels
    【建模】UML类关系分析
    公式提取软件mathpix
    ROS多线程编程
    ROS节点的初始化及退出详解(ros::init、SIGINT、ros::ok、ros::NodeHandle
    ROS 日志消息(C++)
    Python 中的 if __name__ == '__main__' 该如何理解
  • 原文地址:https://www.cnblogs.com/limingxian537423/p/7374025.html
Copyright © 2011-2022 走看看