首页 技术 正文
技术 2022年11月22日
0 收藏 765 点赞 4,305 浏览 4439 个字

最近做了一个项目,使用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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,427
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,244
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,687
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726