MyBatis generator (postgres)-----生成Dto、Dao、Mapping
来源:互联网 发布:扫号软件 编辑:程序博客网 时间:2024/06/06 05:05
一.eclipse Mybatis generator 插件安裝
二.MyBatis generator (postgres)—–生成Dto、Dao、Mapping
一.eclipse Mybatis generator 插件安裝
1.自動安裝
—-打开eclipse,点击Help>Software Update
—-选择 “Available Software” 标签,点击 “Add Site” 按钮
—-输入以下信息:
Location:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/
—-点击ok,自动进入 “mybatis generator Feature”
—-点击“install”按钮进行安装。。。。mybatis generator 插件安装完成
2.手動安裝
—-教程http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html
—-插件下載http://jingyan.baidu.com/article/9faa7231506ed8473c28cbee.html
二.MyBatis generator (postgres)—–生成Dto、Dao、Mapping
由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,所以查资料发现有现成的工具可以自动生成底层模型类、Dao接口类甚至Mapping映射文件.
—–創建表
CREATE TABLE worker
(
id
varchar(50) NOT NULL,
username
varchar(18) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
password
varchar(18) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
—–配置generator config
generatorConfig.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="/home/peng.zhang/zpeng/sources/myjars/postgresql-9.4-1201.jdbc4.jar" /> <context id="context1"> <jdbcConnection driverClass="org.postgresql.Driver" connectionURL="jdbc:postgresql://127.0.0.1:5432/postgres" userId="postgres" password="123456" /> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.travelzen.entity" targetProject="MybatisTOPostgresql" /> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="mybatis" targetProject="MybatisTOPostgresql" /> <!-- 生成DAO的包名和位置--> <javaClientGenerator targetPackage="com.travel.dao" targetProject="MybatisTOPostgresql" type="XMLMAPPER" /> <!-- 要生成哪些表--> <table tableName="worker" domainObjectName="WorkerDto" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> <!-- <table schema="zpeng" tableName="stu" domainObjectName="Student" enableSelectByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableDeleteByPrimaryKey="true" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"> <columnOverride column="" property="" /> </table> --> </context></generatorConfiguration>
—–生成(兩種方式)
1.右键配置文件运行:
2.命令: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
*無法正確生成看這裏:
http://www.cnblogs.com/AloneSword/p/3412236.html
1.XML Parser Error on line 13: XML 文档结构必须从头至尾包含在同一个实体内。
貌似配置文件不能加注释!
2.Unexpected error while running MyBatis Generator. Exception getting JDBC Driver
查阅generator官方文档发现指定Jar包路径即可
3.eneration Warnings Occured Table configuration with catalog null, schema null, and table T_LOGIN did not resolve to any tables
忘了建表,数据库中没表当然解析不了………创建表,解析成功,毫无压力
- MyBatis generator (postgres)-----生成Dto、Dao、Mapping
- MyBatis Generator自动生成Dto、Dao、Mapping
- MyBatis Generator 自动生成 Dto、Dao、Mapping
- 使用MyBatis Generator插件自动生成Dto、Dao、Mapping
- 利用mybatis-generator生成dao-pojo-mapping
- mybatis-generator自动生成dao、mapping、model
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- MyBatis学习4---使用MyBatis_Generator生成Dto、Dao、Mapping
- hdoj 3594 Cactus 【仙人掌图的判定】【有向图tarjan求SCC】
- android桌面图标更换后不起效果
- 从layout到extent的演变史(三)
- 第二周第一天
- 文本相似度计算之tf-idf
- MyBatis generator (postgres)-----生成Dto、Dao、Mapping
- NSString
- this指针的用法
- javascript基本包装类型学习笔记之----基本包装类型的基本特点
- 线程范围内访问变量,hashmap实现线程内数据同步
- C语言08 -- 指针
- Android:安装时提示:INSTALL_FAILED_INSUFFICIENT_STORAGE
- 使用pandoc,转换Markdown为PDF
- OC当中常用的字符串方法