Mybatis 自动生成代码,数据库postgresql
最近做了一个项目,使用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的更多相关文章
- 【MyBatis】MyBatis自动生成代码查询之爬坑记
前言 项目使用SSM框架搭建Web后台服务,前台后使用restful api,后台使用MyBatisGenerator自动生成代码,在前台使用关键字进行查询时,遇到了一些很宝贵的坑,现记录如下.为展示 ...
- mybatis自动生成代码插件mybatis-generator使用流程(亲测可用)
mybatis-generator是一款在使用mybatis框架时,自动生成model,dao和mapper的工具,很大程度上减少了业务开发人员的手动编码时间 坐着在idea上用maven构建spri ...
- mybatis 自动生成代码(mybatis generator)
pom.xml 文件配置 引入 mybatis generator <properties> <mysql.connector.version>5.1.44</mysql ...
- springboot mybatis 自动生成代码(maven+IntelliJ IDEA)
1.在pom文件中加入需要的依赖(mybatis-generator-core) 和 插件(mybatis-generator-maven-plugin) <dependency> < ...
- mybatis自动生成代码工具(逆向工程)
MyBatis自动生成实体类(逆向工程) MyBatis属于一种半自动的ORM框架,它需要我们自己编写sql语句和映射文件,但是编写映射文件和sql语句很容易出错,所以mybatis官方提供了Gene ...
- 自定义Mybatis自动生成代码规则
前言 大家都清楚mybatis-generate-core 这个工程提供了获取表信息到生成model.dao.xml这三层代码的一个实现,但是这往往有一个痛点,比如需求来了,某个表需要增加字段,肯定需 ...
- MyBatis自动生成代码示例
在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...
- mybatis自动生成代码
使用maven集成mybatis-generator插件生成Mybatis的实体类,DAO接口和Map映射文件 本例中,使用的是mysql数据库 前提:表已经建好 mybatis框架的jar包,数据 ...
- Mybatis 自动生成代码
准备条件: 将下面的文件放入同一目录下 操作步骤: 1/ 在 generatorConfig.xml 中配置相关的参数,与需要被自动生成的表 也可以 执行项目中的MybatisConfigAutoGe ...
随机推荐
- runOnUiThread更新主线程
更新UI采用Handle+Thread,需要发送消息,接受处理消息(在回调方法中处理),比较繁琐.除此之外,还可以使用runOnUiThread方法. 利用Activity.runOnUiThre ...
- 【转】IntelliJ IDEA关联SVN
http://blog.csdn.net/xdd19910505/article/details/52756417 问题描述: IntelliJ IDEA安装之后,使用SVN进行提交或更新以及检出代码 ...
- 《Excel效率手册:早做完,不加班》
<Excel效率手册:早做完,不加班> 基本信息 作者: 陈锡卢 杨明辉 出版社:清华大学出版社 ISBN:9787302350743 上架时间:2014-5-8 出版日期:2014 ...
- java将XML文档转换成json格式数据
功能 将xml文档转换成json格式数据 说明 依赖包:1. jdom-2.0.2.jar : xml解析工具包;2. fastjson-1.1.36.jar : 阿里巴巴研发的高性能json工具包 ...
- FMX.Controls单元 中图形矩阵变换
procedure TControl.DoMatrixChanged(Sender: TObject);var TranslateMatrix, ScaleMatrix, RotMatrix: TMa ...
- [leetcode]Evaluate Reverse Polish Notation @ Python
原题地址:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ 题意: Evaluate the value of an ...
- [leetcode]Unique Binary Search Trees II @ Python
原题地址:https://oj.leetcode.com/problems/unique-binary-search-trees-ii/ 题意:接上一题,这题要求返回的是所有符合条件的二叉查找树,而上 ...
- Multiply Strings leetcode java
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...
- 构建-4 dependencies 依赖管理
官方文档 Add build dependencies The Gradle build system in Android Studio makes it easy to include exter ...
- 解决 win7 注册com组件失败问题
解决 win7 注册com组件失败问题 运行:regsvr32 xxx.ocx 提示:模块 "xxx.ocx" 已加载,但对调用 dllregisterserver 的调用失败,错 ...