从命令行运行 MyBatis Generator
一、准备
1. 获取最新jar包
2. 获取xml dtd
<?xml version="1.0" encoding="UTF-8"?> <!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--> <!--
This DTD defines the structure of the MyBatis generator configuration file.
Configuration files should declare the DOCTYPE as follows: <!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> Please see the documentation included with MyBatis generator for details on each option
in the DTD. You may also view documentation on-line here: http://mybatis.org/docs/generator --> <!--
The generatorConfiguration element is the root element for configurations.
-->
<!ELEMENT generatorConfiguration (properties?, classPathEntry*, context+)> <!--
The properties element is used to define a standard Java properties file
that contains placeholders for use in the remainder of the configuration
file.
-->
<!ELEMENT properties EMPTY>
<!ATTLIST properties
resource CDATA #IMPLIED
url CDATA #IMPLIED> <!--
The context element is used to describe a context for generating files, and the source
tables.
-->
<!ELEMENT context (property*, plugin*, commentGenerator?, jdbcConnection, javaTypeResolver?,
javaModelGenerator, sqlMapGenerator?, javaClientGenerator?, table+)>
<!ATTLIST context id ID #REQUIRED
defaultModelType CDATA #IMPLIED
targetRuntime CDATA #IMPLIED
introspectedColumnImpl CDATA #IMPLIED> <!--
The jdbcConnection element is used to describe the JDBC connection that the generator
will use to introspect the database.
-->
<!ELEMENT jdbcConnection (property*)>
<!ATTLIST jdbcConnection
driverClass CDATA #REQUIRED
connectionURL CDATA #REQUIRED
userId CDATA #IMPLIED
password CDATA #IMPLIED> <!--
The classPathEntry element is used to add the JDBC driver to the run-time classpath.
Repeat this element as often as needed to add elements to the classpath.
-->
<!ELEMENT classPathEntry EMPTY>
<!ATTLIST classPathEntry
location CDATA #REQUIRED> <!--
The property element is used to add custom properties to many of the generator's
configuration elements. See each element for example properties.
Repeat this element as often as needed to add as many properties as necessary
to the configuration element.
-->
<!ELEMENT property EMPTY>
<!ATTLIST property
name CDATA #REQUIRED
value CDATA #REQUIRED> <!--
The plugin element is used to define a plugin.
-->
<!ELEMENT plugin (property*)>
<!ATTLIST plugin
type CDATA #REQUIRED> <!--
The javaModelGenerator element is used to define properties of the Java Model Generator.
The Java Model Generator builds primary key classes, record classes, and Query by Example
indicator classes.
-->
<!ELEMENT javaModelGenerator (property*)>
<!ATTLIST javaModelGenerator
targetPackage CDATA #REQUIRED
targetProject CDATA #REQUIRED> <!--
The javaTypeResolver element is used to define properties of the Java Type Resolver.
The Java Type Resolver is used to calculate Java types from database column information.
The default Java Type Resolver attempts to make JDBC DECIMAL and NUMERIC types easier
to use by substituting Integral types if possible (Long, Integer, Short, etc.)
-->
<!ELEMENT javaTypeResolver (property*)>
<!ATTLIST javaTypeResolver
type CDATA #IMPLIED> <!--
The sqlMapGenerator element is used to define properties of the SQL Map Generator.
The SQL Map Generator builds an XML file for each table that conforms to iBATIS'
SqlMap DTD.
-->
<!ELEMENT sqlMapGenerator (property*)>
<!ATTLIST sqlMapGenerator
targetPackage CDATA #REQUIRED
targetProject CDATA #REQUIRED> <!--
The javaClientGenerator element is used to define properties of the Java client Generator.
The Java Client Generator builds Java interface and implementation classes
(as required) for each table.
If this element is missing, then the generator will not build Java Client classes.
-->
<!ELEMENT javaClientGenerator (property*)>
<!ATTLIST javaClientGenerator
type CDATA #REQUIRED
targetPackage CDATA #REQUIRED
targetProject CDATA #REQUIRED
implementationPackage CDATA #IMPLIED> <!--
The table element is used to specify a database table that will be the source information
for a set of generated objects.
-->
<!ELEMENT table (property*, generatedKey?, columnRenamingRule?, (columnOverride | ignoreColumn)*) >
<!ATTLIST table
catalog CDATA #IMPLIED
schema CDATA #IMPLIED
tableName CDATA #REQUIRED
alias CDATA #IMPLIED
domainObjectName CDATA #IMPLIED
enableInsert CDATA #IMPLIED
enableSelectByPrimaryKey CDATA #IMPLIED
enableSelectByExample CDATA #IMPLIED
enableUpdateByPrimaryKey CDATA #IMPLIED
enableDeleteByPrimaryKey CDATA #IMPLIED
enableDeleteByExample CDATA #IMPLIED
enableCountByExample CDATA #IMPLIED
enableUpdateByExample CDATA #IMPLIED
selectByPrimaryKeyQueryId CDATA #IMPLIED
selectByExampleQueryId CDATA #IMPLIED
modelType CDATA #IMPLIED
escapeWildcards CDATA #IMPLIED
delimitIdentifiers CDATA #IMPLIED
delimitAllColumns CDATA #IMPLIED> <!--
The columnOverride element is used to change certain attributes of the column
from their default values.
-->
<!ELEMENT columnOverride (property*)>
<!ATTLIST columnOverride
column CDATA #REQUIRED
property CDATA #IMPLIED
javaType CDATA #IMPLIED
jdbcType CDATA #IMPLIED
typeHandler CDATA #IMPLIED
delimitedColumnName CDATA #IMPLIED> <!--
The ignoreColumn element is used to identify a column that should be ignored.
No generated SQL will refer to the column, and no property will be generated
for the column in the model objects.
-->
<!ELEMENT ignoreColumn EMPTY>
<!ATTLIST ignoreColumn
column CDATA #REQUIRED
delimitedColumnName CDATA #IMPLIED> <!--
The generatedKey element is used to identify a column in the table whose value
is calculated - either from a sequence (or some other query), or as an identity column.
-->
<!ELEMENT generatedKey EMPTY>
<!ATTLIST generatedKey
column CDATA #REQUIRED
sqlStatement CDATA #REQUIRED
identity CDATA #IMPLIED
type CDATA #IMPLIED> <!--
The columnRenamingRule element is used to specify a rule for renaming
columns before the corresponding property name is calculated
-->
<!ELEMENT columnRenamingRule EMPTY>
<!ATTLIST columnRenamingRule
searchString CDATA #REQUIRED
replaceString CDATA #IMPLIED> <!--
The commentGenerator element is used to define properties of the Comment Generator.
The Comment Generator adds comments to generated elements.
-->
<!ELEMENT commentGenerator (property*)>
<!ATTLIST commentGenerator
type CDATA #IMPLIED>
二、说明
mybatis-generator-core-1.3.2.jar 是可执行jar
主函数类是 Main-Class: org.mybatis.generator.api.ShellRunner (见jar包中 /META-INF/MANIFEST.MF )
需要jdk环境,环境变量PATH需要设置
编写.bat 文件(用来执行java 命令),文件内容如下:
java -jar mybatis-generator-core-1.3..jar -configfile generator.xml
准备适当的数据库驱动jar包,本例使用oracle驱动点击下载ojdbc14
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="./ojdbc14.jar" /> <context id="OracleTables" targetRuntime="MyBatis3"> <commentGenerator>
<property name="suppressAllComments" value="false" />
<property name="suppressDate" value="true" />
</commentGenerator> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@//172.16.50.67:1521/orcl"
userId="e_channel"
password="e_channel_test">
</jdbcConnection> <javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver> <!-- 模型 Plain Ordinary Java Object -->
<javaModelGenerator targetPackage="cn.zno.pojo" targetProject="./">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- sql -->
<sqlMapGenerator targetPackage="cn.zno.dao" targetProject="./">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 调用接口 Data Access Object -->
<javaClientGenerator type="XMLMAPPER" targetPackage="cn.zno.dao" targetProject="./">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- table+ -->
<table schema="" tableName="PERSON" domainObjectName="Person" ></table> </context>
</generatorConfiguration>
表结构如下:
create table PERSON
(
ID VARCHAR2(10),
NAME VARCHAR2(10),
AGE NUMBER
)
三、清单
generator.bat
generator.xml
mybatis-generator-core-1.3.2.jar
ojdbc14.jar
四、生成
D:.
│ generator.bat
│ generator.xml
│ mybatis-generator-core-1.3.2.jar
│ ojdbc14.jar
│
└─cn
└─zno
├─dao
│ PersonMapper.java
│ PersonMapper.xml
│
└─pojo
Person.java
PersonExample.java
五、获取地址
git@github.com:witaste/mybatis-generator-commondline.git
从命令行运行 MyBatis Generator的更多相关文章
- 从命令行运行django数据库操作
从命令行运行django数据库操作,报错: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_T ...
- python命令行运行在win和Linux系统的不同
今天,在完成一个小的python习题,习题的主要内容是读取一个帮助模块,并保存到本地文件. 知道是用pydoc进行模块的读取,但是在windows系统下,调用os模块之后,结果总是为空. 核心语句: ...
- jmeter命令行运行-分布式测试
上一篇文章我们说到了jmeter命令行运行但是是单节点下的, jmeter底层用java开发,耗内存.cpu,如果项目要求大并发去压测服务端的话,jmeter单节点难以完成大并发的请求,这时就需要对j ...
- jmeter命令行运行-单节点
jmeter有自己的GUI页面,但是当线程数很多或者现在有很多的测试场景都是基于linux下进行压测,这时我们可以使用jmeter的命令行方式来执行测试,该篇文章介绍jmeter单节点命令运行方式. ...
- 含有package关键字的java文件在命令行运行报错
程序中含有package关键字,使用命令行运行程序时出现"找不到或无法加载主类",而使用Eclipse软件可以正常运行程序的可能解决办法. 在包下的类,在Java源文件的地方编译后 ...
- 命令行运行Android Robotium自动化用例或单元测试用例
本文目录 1.运行所有的测试用例 2.运行单个测试类或某个TestSuite 3.运行某个测试类里面的某个测试方法 4.运行两个不同的测试类或类中的方法 命令行运行Android Robotium自动 ...
- loadrunner 运行场景-命令行运行场景
运行场景-命令行运行场景 by:授客 QQ:1033553122 1 相对路径与绝对路径 在场景中为脚本指定一个相对位置,可以是相对于当前场景目录或lr安装目录. 当你运行一个场景,场景自动从这个相对 ...
- 安装了nodejs后在命令行运行npm报错
安装了nodejs后在命令行运行npm报错:Error: Cannot find module 'internal/util/types' 解决方法:删除目录“C:\Users\mengxiaobo\ ...
- dos命令行运行.class源文件错误解决办法
dos命令行运行java源文件 public static void main(String[] args) throws IOException { // TODO Auto-generated m ...
随机推荐
- 【BZOJ】1012: [JSOI2008]最大数maxnumber /【洛谷】1198(线段树)
Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插 ...
- 浅谈PHP面向对象编程(六、自动加载及魔术方法)
6.0 自动加载及魔术方法 6.1 自动加载 在PHP开发过程中,如果希望从外部引入一个class.通常会使用incluae和requre方法把定义这个class的文件包含进来.但是,在大型的开发项 ...
- 03——微信小程序官方demo讲解——page部分
一个page由一个文件夹以及文件夹下四个文件组成. 比如一个页面叫index.则需要在pages目录下新建一个index目录,且包含由index+类型(js\wxml\wxss\json)为名组成的若 ...
- EasyUI介绍及常见问题
JQuery Easy UI介绍 1.JQuery Easy UI环境搭建和调试: https://jingyan.baidu.com/article/67508eb4342f9f9cca1ce426 ...
- 梯度下降(Gradient descent)
首先,我们继续上一篇文章中的例子,在这里我们增加一个特征,也即卧室数量,如下表格所示: 因为在上一篇中引入了一些符号,所以这里再次补充说明一下: x‘s:在这里是一个二维的向量,例如:x1(i)第i间 ...
- 18_java之集合Collection
01集合使用的回顾 *A:集合使用的回顾 *a.ArrayList集合存储5个int类型元素 public static void main(String[] args) { ArrayList< ...
- HALCON形状匹配(转)
LIntExport Herror create_shape_model( const Hobject& Template , //reduce_domain后的模板图像 Hlong N ...
- Halcon算子之shape_trans,用于变换区域的形状
函数原型:shape_trans(Region : RegionTrans : Type : ) *shape_trans*仍然是区域,smallest_rectangle1可以获得四个角的坐标 函数 ...
- 「小程序JAVA实战」小程序头像图片上传(上)(43)
转自:https://idig8.com/2018/09/08/xiaochengxujavashizhanxiaochengxutouxiangtupianshangchuan40/ 在微信小程序中 ...
- mysql update更新带子查询的实现方式
现在要做一下数据移植,需要更新相关的数据,需要在mysql中更新时不能将更新的表作为查询的表. 总结一下: 一:单表更新时 例如: update customer set category = 1 W ...