最近做了一个项目,使用Mybatis自动生成代码,下面做一下总结,被以后参考:

一、提前准备:

1、工具类:mybatis-generator-core-1.3.2.jar

2、postgresql驱动:postgresql-9.2-1003-jdbc4.jar

3、xml文件

这些我都上传到了附件上,下载链接:Download

二、XML详解

咱们的核心配置文件:mybatisGeneratorConfig.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="/Users/liqiu/git/study/web/soft/postgresql-9.2-1003-jdbc4.jar" />
<context id="tts2">
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://l-***.com:5433/crm"
userId="menpiao_dev" password="d**904-8dce-**d0-bb1b-79***cc">
</jdbcConnection> <javaModelGenerator targetPackage="com.qunar.study.entity" targetProject="/Users/liqiu/git/study/web/src/main/java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="mybatis" targetProject="/Users/liqiu/git/study/web/src/main/resources/">
</sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.qunar.study.mapper" targetProject="/Users/liqiu/git/study/web/src/main/java">
<property name="enableSubPackages" value="false" />
</javaClientGenerator> <table schema="public" tableName="users" domainObjectName="Users"></table>
<table schema="public" tableName="region_manager" domainObjectName="RegionManager"></table>
<table schema="public" tableName="region" domainObjectName="Region"></table>
<table schema="public" tableName="merchant" domainObjectName="Merchant"></table>
<table schema="public" tableName="state_machine" domainObjectName="StateMachine"></table>
<table schema="public" tableName="work_log" domainObjectName="WorkLog"></table>
<table schema="public" tableName="contract" domainObjectName="Contract"></table>
<table schema="public" tableName="notice" domainObjectName="Notice"></table>
<table schema="public" tableName="contact_person_info" domainObjectName="ContactPersonInfo"></table>
<table schema="public" tableName="express" domainObjectName="Express"></table>
<table schema="public" tableName="comment" domainObjectName="Comment"></table>
<!--
<table schema="public" tableName="operation" domainObjectName="Operation" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" ></table>
-->
</context>
</generatorConfiguration>

三、执行代码:

java -jar /Users/liqiu/git/study/web/soft/mybatis-generator-core-1.3.2/lib/mybatis-generator-core-1.3.2.jar -configfile /Users/liqiu/git/study/web/soft/mybatisGeneratorConfig.xml -overwrite

这时就可以看见生成的代码了

├── src
│   ├── main
│   │   ├── java
│   │   │   ├── com
│   │   │   │   └── qunar
│   │   │   │   └── study
│   │   │   │   ├── entity
│   │   │   │   │   ├── Comment.java
│   │   │   │   │   ├── CommentExample.java
│   │   │   │   │   ├── ContactPersonInfo.java
│   │   │   │   │   ├── ContactPersonInfoExample.java
│   │   │   │   │   ├── Contract.java
│   │   │   │   │   ├── ContractExample.java
│   │   │   │   │   ├── Express.java
│   │   │   │   │   ├── ExpressExample.java
│   │   │   │   │   ├── Merchant.java
│   │   │   │   │   ├── MerchantExample.java
│   │   │   │   │   ├── Notice.java
│   │   │   │   │   ├── NoticeExample.java
│   │   │   │   │   ├── Operation.java
│   │   │   │   │   ├── OperationExample.java
│   │   │   │   │   ├── Region.java
│   │   │   │   │   ├── RegionExample.java
│   │   │   │   │   ├── RegionManager.java
│   │   │   │   │   ├── RegionManagerExample.java
│   │   │   │   │   ├── StateMachine.java
│   │   │   │   │   ├── StateMachineExample.java
│   │   │   │   │   ├── Users.java
│   │   │   │   │   ├── UsersExample.java
│   │   │   │   │   ├── WorkLog.java
│   │   │   │   │   └── WorkLogExample.java
│   │   │   │   └── mapper
│   │   │   │   ├── CommentMapper.java
│   │   │   │   ├── ContactPersonInfoMapper.java
│   │   │   │   ├── ContractMapper.java
│   │   │   │   ├── ExpressMapper.java
│   │   │   │   ├── MerchantMapper.java
│   │   │   │   ├── NoticeMapper.java
│   │   │   │   ├── OperationMapper.java
│   │   │   │   ├── RegionManagerMapper.java
│   │   │   │   ├── RegionMapper.java
│   │   │   │   ├── StateMachineMapper.java
│   │   │   │   ├── UsersMapper.java
│   │   │   │   └── WorkLogMapper.java
│   │   │   └── test
│   │   │   └── qunar
│   │   │   └── com
│   │   │   └── web
│   │   │   └── App.java
│   │   └── resources
│   │   └── mybatis
│   │   ├── CommentMapper.xml
│   │   ├── ContactPersonInfoMapper.xml
│   │   ├── ContractMapper.xml
│   │   ├── ExpressMapper.xml
│   │   ├── MerchantMapper.xml
│   │   ├── NoticeMapper.xml
│   │   ├── OperationMapper.xml
│   │   ├── RegionManagerMapper.xml
│   │   ├── RegionMapper.xml
│   │   ├── StateMachineMapper.xml
│   │   ├── UsersMapper.xml
│   │   └── WorkLogMapper.xml

注:这里的核心是路径,最好都是用绝对路径

Mybatis 自动生成代码,数据库postgresql的更多相关文章

  1. 【MyBatis】MyBatis自动生成代码查询之爬坑记

    前言 项目使用SSM框架搭建Web后台服务,前台后使用restful api,后台使用MyBatisGenerator自动生成代码,在前台使用关键字进行查询时,遇到了一些很宝贵的坑,现记录如下.为展示 ...

  2. mybatis自动生成代码插件mybatis-generator使用流程(亲测可用)

    mybatis-generator是一款在使用mybatis框架时,自动生成model,dao和mapper的工具,很大程度上减少了业务开发人员的手动编码时间 坐着在idea上用maven构建spri ...

  3. mybatis 自动生成代码(mybatis generator)

    pom.xml 文件配置 引入 mybatis generator <properties> <mysql.connector.version>5.1.44</mysql ...

  4. springboot mybatis 自动生成代码(maven+IntelliJ IDEA)

    1.在pom文件中加入需要的依赖(mybatis-generator-core) 和 插件(mybatis-generator-maven-plugin) <dependency> < ...

  5. mybatis自动生成代码工具(逆向工程)

    MyBatis自动生成实体类(逆向工程) MyBatis属于一种半自动的ORM框架,它需要我们自己编写sql语句和映射文件,但是编写映射文件和sql语句很容易出错,所以mybatis官方提供了Gene ...

  6. 自定义Mybatis自动生成代码规则

    前言 大家都清楚mybatis-generate-core 这个工程提供了获取表信息到生成model.dao.xml这三层代码的一个实现,但是这往往有一个痛点,比如需求来了,某个表需要增加字段,肯定需 ...

  7. MyBatis自动生成代码示例

    在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...

  8. mybatis自动生成代码

    使用maven集成mybatis-generator插件生成Mybatis的实体类,DAO接口和Map映射文件 本例中,使用的是mysql数据库 前提:表已经建好  mybatis框架的jar包,数据 ...

  9. Mybatis 自动生成代码

    准备条件: 将下面的文件放入同一目录下 操作步骤: 1/ 在 generatorConfig.xml 中配置相关的参数,与需要被自动生成的表 也可以 执行项目中的MybatisConfigAutoGe ...

随机推荐

  1. C#编程(五十七)----------位数组

    位数组 如果需要处理很多位,就可以使用BitArray类和BitVector32.BitArray位于命名空间System.Collections中. BitVector32位于命名空间System. ...

  2. arcgis10.5.1 对齐要素

    许可级别:BasicStandardAdvanced 摘要 标识地理处理工具用于标识搜索距离中输入要素与目标要素的不一致部分并使其与目标要素一致. 插图 用法 警告: 此工具用于修改输入数据.有关详细 ...

  3. Ioc模式和MEF

    IOC模式 Ioc模式(又称DI:Dependency Injection 依赖注射). 分离关注( Separation of Concerns : SOC)是Ioc模式和AOP产生最原始动力,通过 ...

  4. SVG.js 图案使用和use引用

    一.SVG.Pattern 图案设置 var draw = SVG('svg1').size(300, 300); //SVG.Pattern 图案设置 var pattern = draw.patt ...

  5. 解读SSD中的Default box(Prior Box)

    1:SSD更具体的框架如下: 2: Prior Box 缩进在SSD中引入了Prior Box,实际上与anchor非常类似,就是一些目标的预选框,后续通过softmax分类+bounding box ...

  6. iOS:仿写探探App动画

    一.简单介绍 探探动画比较新颖,这也是它在众多交友软件中火热的一个特色.实现这种动画的方式可以有两种方式实现: 1.使用转场动画实现  2.使用CollectionView自定义布局实现, 此处我提供 ...

  7. Java学习笔记——IO操作之以图片地址下载图片

    以图片地址下载图片 读取给定图片文件的内容,用FileInputStream public static byte[] mReaderPicture(String filePath) { byte[] ...

  8. Linux中如何查看文件夹的大小

    直接查看当前文件夹的大小: du –sh 只看文件夹的名字里包含某字符串的子文件夹的大小: du –h –d 1 | grep "BACKEND" 我的linux系统被阉割的比较厉 ...

  9. gradlew 命令行 build 调试 构建错误 Manifest merger failed MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  10. mybatis plus 主键生成 Twitter雪花算法 id 及修改id为字符型

    mybatis plus配置主键生成策略为2,就是 使用Twitter雪花算法 生成id spring boot中配置为: GlobalConfiguration conf = new GlobalC ...