Myeclipse配置Mybatis_generator生成mapper,model,client

在使用mybatis对接数据的时候,手动写mapper,model,client会比较费时间,可以试用mybatis_gererator来生成难度比较大的mybatis配置文件.

先要用myeclipse创建java工程.

将mysql-connector-java-5.1.18.jar放到指定的目录项目,并且配置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="/opt/app-w/gitresp/testcore/src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.18.jar" />
    <context id="context1">
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://ip:3306/xx?useUnicode=true&amp;characterEncoding=UTF-8"
            userId="root" password="123456" />
        <javaModelGenerator targetPackage="model"
            targetProject="testcore" />
        <sqlMapGenerator targetPackage="mapper" targetProject="testcore" />
        <!--    数据库 表名 生成名 -->
        <javaClientGenerator targetPackage="client"
            targetProject="testcore" type="XMLMAPPER" />
        <table schema="xx" tableName="xx"
            domainObjectName="xx">
        </table>
    </context>
</generatorConfiguration>

然后到github上下载mybatis/generator插件,git clone https://github.com/mybatis/generator.git.并且把目录generator/eclipse/UpdateSite下面的features和plugins拷贝到myeclipse相应的目录下面.

这样就可以右击在myeclipse中的generatorConfig.xml,找到生成mybatis artifacts选项,就可以生成mapper,model,client,如下图:

如果出现错误:Unexpected error while running MyBatis Generator. Exception getting JDBC Driver

这个就说明是<classPathEntry

location="/opt/app-w/gitresp/testcore/src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.18.jar" />

这里路径有问题,配置好就可以解决!

时间: 2024-08-03 09:19:09

Myeclipse配置Mybatis_generator生成mapper,model,client的相关文章

使用MyBatis_Generator生成Dto、Dao、Mapping

转载地址:http://blog.csdn.net/wyc_cs/article/details/9023117 由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,所以查资料发现有现成的工具可以自动生成底层模型类.Dao接口类甚至Mapping映射文件. 一.建立表结构 CREATE TABLE `user` (   `id` varchar(50) NOT NULL,   `username` varchar(18) C

使用MyBatis-Gererator自动生成Dao.Model.Mapping相关文件

一.在MyEclipse中使用Maven项目下使用MyBatis-Gererator自动生成Dao.Model.Mapping相关文件 1.关于Mybatis-Generator的下载可以到这个地址:https://github.com/mybatis/generator/releases 2.查找能够匹配maven的下载配置文件,将匹配的相关文件配置到maven项目下的pom.xml文件中 3.复制以下二中的generatorConfig.xml文件,到myEclipse中创建的maven项目

MyEclipse Hibernate反向工程生成实体类

不废话,直接上步骤 step1.Window -> Open Perspective -> MyEclipse Database Explorer 到DB Broswer界面 step2.右键 -> New,新建一个数据库连接 step3.创建一个java项目 step4.给项目添加Hibernate Capabilities 项目 -> 右键 -> MyEclipse -> Add Hibernate Capabilities Add Hibernate Capabi

在MyEclipse配置自己安装的Tomcat(2014.08.18)

今天因为要在tomcat下运行一个java项目,第一次嘛,遇到了不少问题,总结分享一下: 第一次,我直接将 MyEclipse 生成的项目放到 tomcat 安装目录的 webapps 目录下,运行出现404,无法访问. 然后想了想,发现这是个错误的做法.应该先通过 MyEclipse 将项目部署到 Tomcat 下: 然后, MyEclipse 自带了 tomcat,我要配置自己安装的 TomCat : (请看参考资料:http://jingyan.baidu.com/article/4853

使用myeclipse创建带注解的model实体类

1.先新建JPA项目: 如果没有就点击左下角的Show All Wizards. 点两次Next后,点击Finish即可,中间不用任何操作 (点第二次Next后会出现连接到所在数据库,先不管) 连接数据库的如下图的Connection 点击FINISH后如图 2.打开Myelipse Database Explorer视图 在DB Browser栏中右键新建连接:New... 填写信息:记得导入包,否则会报错 点击Test Driver:连接成功即可 找到对应的数据库的表 选中将要生成注解mod

通过Hibernate将数据库在myeclipse中逆向生成

1.首先准备好数据库. 2.在MyEclipse的右上角切换透视图,切换到MyEclipse Database Explorer 3.在最左边点击右键,选择New(也就是新建一个数据库连接),然后编写第一个页面, Driver template: MySQL Connector/J (因为是建立数据库连接) Driver name    :icloud(这个名字随便起,方便以后使用) Connection URL : jdbc:myslq://localhost:3306/icloud?useU

mybatis自己主动生成mapper,dao,映射文件

一.先创建数据脚本,这里用的mysql数据脚本 drop table VOTE_ITEM; drop table VOTE_OPTION; drop table VOTE_SUBJECT; drop table VOTE_USER;     create table VOTE_USER (   VU_USER_ID   int(8) primary key,     VU_USER_NAME VARCHAR(20) not null,     VU_PASSWORD  VARCHAR(20) n

mybatis自动生成mapper,dao,映射文件

一.先创建数据脚本,这里用的mysql数据脚本 drop table FILMINFO; drop table FILMTYPE; create table FILMINFO ( FILMID int primary key auto_increment, FILMNAME VARCHAR(50) not null, TYPEID int not null, ACTOR VARCHAR(255), DIRECTOR VARCHAR(50), TICKETPRICE int not null );

mybatis 自动生成 mapper

目录 生成命令 oracle 的配置 mysql 的配置 解决问题 生成的 mapper.xml 中有重复代码 无法生成 selectByPrimaryKey.deleteByPrimaryKey 等方法 相关文章 生成命令 java -jar generator.jar -configfile generator.xml -overwrite oracle 的配置 <?xml version="1.0" encoding="UTF-8"?> <!