一直依赖我都不是很喜欢自动生成代码的工具,因为生成出来的代码不是很好的,适应性不好!
再说,自己写一些代码也是消耗不了多少时间的。但是应同学的要求,我帮他安装了MyBatis Generator。
pom.xml:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<
plugins
>
<
plugin
>
<
groupId
>org.mybatis.generator</
groupId
>
<
artifactId
>mybatis-generator-maven-plugin</
artifactId
>
<
version
>1.3.2</
version
>
<
configuration
>
<
verbose
>true</
verbose
>
<
overwrite
>true</
overwrite
>
</
configuration
>
</
plugin
>
</
plugins
>
<
dependencies
>
<
dependency
>
<
groupId
>org.mybatis.generator</
groupId
>
<
artifactId
>mybatis-generator-core</
artifactId
>
<
version
>1.3.2</
version
>
</
dependency
>
</
dependencies
>
|
在/voicelog/src/main/resource/中放入generatorConfig.xml文件:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<?
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
>
<!-- 设置mysql驱动路径 -->
<
classPathEntry
location
=
"D:\Code\maven3\repo\m2\mysql\mysql-connector-java\5.1.37\mysql-connector-java-5.1.37.jar"
/>
<!-- 此处指定生成针对MyBatis3的DAO -->
<
context
id
=
"context1"
targetRuntime
=
"MyBatis3"
>
<!-- jdbc连接信息 -->
<
jdbcConnection
driverClass
=
"com.mysql.jdbc.Driver"
connectionURL
=
"jdbc:mysql://localhost:3306/yii"
userId
=
"root"
password
=
"root"
/>
<!-- 生成vo对象 -->
<
javaModelGenerator
targetPackage
=
"com.baidu.voice.model"
targetProject
=
"voicelog"
/>
<!-- 生成用于查询的Example对象 -->
<
sqlMapGenerator
targetPackage
=
"com.baidu.voice.model"
targetProject
=
"voicelog"
/>
<!-- 生成DAO的类文件以及配置文件 -->
<
javaClientGenerator
targetPackage
=
"com.baidu.voice.dao"
targetProject
=
"voicelog"
type
=
"XMLMAPPER"
/>
<!-- 想要生成的数据库表,自动化工具会根据该表的结构生成相应的vo对象 -->
<
table
schema
=
""
tableName
=
"admin"
>
</
table
>
</
context
>
</
generatorConfiguration
>
|
Myeclipse安装MyBatis Generator插件:
http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
安装成功后:
执行即可!
本文转自 梦朝思夕 51CTO博客,原文链接:http://blog.51cto.com/qiangmzsx/1771171
