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 ...
随机推荐
- JQuery攻略(六)菜单导航
jQuery菜单导航的基础应用 此章节有 1.0 页面导航 1.01面包屑菜单 1.02菜单悬停 1.03菜单快捷键 1.04两个单独的菜单 1.05折叠菜单 1.01面包屑菜单 html <b ...
- Android之TextView部分颜色变动
public class StringHandleExampleActivity extends Activity { /** Called when the activity is first cr ...
- .condarc(conda 配置文件)、换国内源
原文地址 https://blog.csdn.net/lanchunhui/article/details/71379555 Configuration — Conda documentation . ...
- 单因素方差分析(One Way ANOVA)
Analysis of variance (ANOVA) is a collection of statistical models and their associated estimation p ...
- [转]五种常见的 PHP 设计模式
FROM : http://www.ibm.com/developerworks/cn/opensource/os-php-designptrns/ 设计模式 一书将设计模式引入软件社区,该书的作者是 ...
- [转]Infobright是一个与MySQL集成的开源数据仓库
[文章作者:张宴 本文版本:v1.1 最后修改:2010.05.18 转载请注明原文链接:http://blog.zyan.cc/infobright/] Infobright是一个与MySQL集成的 ...
- jquery fullPage
FROM : http://www.dowebok.com/77.html 应用: http://txhd.163.com/
- perf 高级命令简介
perf 高级命令简介 1.使用 tracepoint 当 perf 根据 tick 时间点进行采样后,人们便能够得到内核代码中的 hot spot. 使用ls命令来演示 sys_enter 这个tr ...
- how to use perf
Since I did't see here anything about perf which is a relatively new tool for profiling the kernel a ...
- Chart:ECharts
ylbtech-Chart:ECharts ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome, ...