Coder Social home page Coder Social logo

mybatis-mapper's Introduction

做一个项目、如果选择MyBatis框架的话,少不了写xml、dao、model。 Mybatis虽好、但是表多了的话、就要重复写xml、dao、model,对于程序猿来说这工作完全就是ctrl + c ,ctrl + V ,在这方面的操作就浪费了大把时间。

于是出现了自动生成工具,这工具会通过数据库自动反向生成对应的dao,model,xml,能够大大提示开发效率。

下载地址:https://github.com/Jandaes/mybatis-mapper/blob/master/mybatis-generator-core-1.3.2.jar

连接数据库

创建数据库

@本地数据库|center

连接的本地数据库、demodb数据库有两个表

加载驱动jar

支持大部分关系型数据库、只要加载对应的驱动就行,换成本地jar的路径 <classPathEntry location="D:\xxx\mysql-connector-java-5.1.38.jar" />

设置数据库连接

driverClass :不同数据库不同驱动 connectionURL:数据库连接地址 userId:数据库用户名 password:数据库密码 <jdbcConnection driverClass="xx" connectionURL="xxx" userId="xxx" password="xxx">

生成模型[model]的包名和位置

targetPackage:在项目中的包名 targetProject:存在本地的路径 <javaModelGenerator targetPackage="xxx" targetProject="xxx">

生成的配置文件[xml]包名和位置

targetPackage:在项目中的包名 targetProject:存在本地的路径 <sqlMapGenerator targetPackage="xxx" targetProject="xxx">

生成接口[dao]的包名和位置

targetPackage:在项目中的包名 targetProject:存在本地的路径 <javaClientGenerator type="XMLMAPPER" targetPackage="coxxx" targetProject="xxx">

要生成哪些表

我数据库只有两个表、只要写两个配置就行,如果有表关联,也会自动生成关联. tableName:表名 domainObjectName:在项目中Model类名

只要更改这两个就可以了 <table tableName="scene" domainObjectName="Scene" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />

执行生成

进入工具根目录、根目录有一个执行jar、以及一个txt说明文本

如果dos路径是在工具根目录可直接执行当前命令,否则需要输入jar绝对路径!

java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite

结果: @生成成功|center

我打包的generator.xml 、内置我默认配置,可改成你对应的配置就行!

大功告成!

欢迎访问个人博客:http://www.liujilu.com

mybatis-mapper's People

Stargazers

 avatar

Watchers

 avatar

Forkers

xizolv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.