最近做了一个项目,使用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. JS 判断 undefined 类型

    typeof 返回的是字符串,有六种可能:"number"."string"."boolean"."object".&q ...

  2. 关于面试总结7-linux篇

    前言 现在做测试的出去面试,都会被问到linux,不会几个linux指令都不好意思说自己是做测试的了,本篇收集了几个被问的频率较高的linux面试题 常用指令 1.说出10个linux常用的指令 ls ...

  3. Java获取URL链接的文件类型

    问题发生: Java从网络批量读取图片并保存至本网站服务器后再插入文章中 今天转入一篇文章 http://news.qq.com/a/20170605/045860.htm 发现图片未能成功上传 查看 ...

  4. [Android] Implementation vs API dependency

    原文链接: https://jeroenmols.com/blog/2017/06/14/androidstudio3/ https://blog.csdn.net/lonewolf521125/ar ...

  5. 分享到微信、微博、QQ空间、QQ微博

    一:分享到微信 //分享到微信$("#weixin").bind("click", function () {    var p = {        url: ...

  6. window.name实现的跨域数据传输 JavaScript跨域总结与解决办法

    原文地址:  http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html#m4 什么是跨域 1.document.domain+ifr ...

  7. Spring Data JPA @Column 注解无效 打出的语句有下划线

    最近再写一个Restful API的小例子,遇到这样一个问题,在Spring Boot 下使用CrudRepository,总是提示如下错误: Caused by: java.sql.SQLSynta ...

  8. SQL Server 数据库项目

    ylbtech-.NET Framework: SQL Server 数据库项目 SQL Server 数据库项目 类型:SQL Server 用于创建 SQL Server 数据库的项目 1. 新建 ...

  9. Android ActionBar使用介绍

    一.什么是ActionBar 有图有真相,看一下图片就了解的差不多了 对于大多数应用,操作栏可以分割为 4 个不同的功能区域. 1. 应用图标 应用图标是您应用的标志.在应用图标位置摆放您自己的 lo ...

  10. 深度学习Github排名,很不错的介绍

    今天看到这篇文章,把深度学习github排名靠前的项目,介绍了一下,很不错: https://blog.csdn.net/yH0VLDe8VG8ep9VGe/article/details/81611 ...