码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis generator

时间:2017-06-02 20:20:44      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:使用   file   mysql   upd   try   sch   插件   注意   lips   

今天特意加班,主要为了弄懂Spring Mvc 和 mybatis 怎么去使用。然后手写映射文件确实有点麻烦,去上网找了自动生成的方法,如下:

 

  mybatis generator 自动生成映射文件 

    首先,下载jar包

      http://download.csdn.net/download/varyall/7468405

      (这个链接算是我找过比较稳定的,其他不是外网就是什么的,反正慢。不喜勿喷,若不行则麻烦自己去找了)

    下载完成之后解压出来,拿到我们需要的jar包   ——  mybatis-generator-core-1.3.2.jar  放在一个文件夹里,注意!!!一定要是英文名称的

    然后在jar包在的地方写一个  xml  ,内容如下:(我的 xml 和 jar 以及下文提到的 txt 文件都在 D:\CodeTool\generator 文件夹里,并且在此目录下多创建了一个空文件夹,用来存放等会生成的映射文件)

 

 1 <?xml version="1.0"  encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration  
 3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"  
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 <generatorConfiguration>
 6   
 7   <!-- 指定数据连接驱动jar地址 -->
 8   <classPathEntry location="D:\CodeTool\jar\mysql-connector-java-5.1.7-bin.jar" />
 9   <context id="my" targetRuntime="MyBatis3">
10     <commentGenerator>
11     <!-- 是否取消注释 -->
12     <property name="suppressAllComments" value="true" />
13     <!-- 是否生成注释代时间戳 -->
14     <!-- <property name="suppressDate" value="true" />-->
15     </commentGenerator>
16     
17     <!--数据库连接URL,用户名,密码 -->
18     <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
19             connectionURL="jdbc:mysql://localhost:3306/数据库名" userId="用户名"  
20             password="密码" />
21     
22     <!-- 生成实体类的包名和位置 -->
23     <javaModelGenerator targetPackage="testMabatis.model"  
24             targetProject="D:\CodeTool\generator\src"><property name="enableSubPackages" value="true" /><property name="trimStrings" value="true" /></javaModelGenerator>
25     
26     <!-- 生成映射文件包名和位置 -->
27     <sqlMapGenerator targetPackage="testMabatis.mapping"  
28             targetProject="D:\CodeTool\generator\src"><property name="enableSubPackages" value="true" /></sqlMapGenerator>
29     
30     <!-- 生成dao的包名和位置 -->
31     <javaClientGenerator targetPackage="testMabatis.dao"  
32             targetProject="D:\CodeTool\generator\src"><property name="enableSubPackages" value="true" /></javaClientGenerator>
33     
34     <!-- 要生成的数据库表,更改tableName和 domainObjectName即可-->
35     
36     <table  tableName="数据库表名"  
37             domainObjectName="生成的类名" enableCountByExample="false"  
38             enableUpdateByExample="false" enableDeleteByExample="false"  
39             enableSelectByExample="false" selectByExampleQueryId="false"/>
40       <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
41                 是否生成 example类 -->
42       
43       <!-- 忽略列,不生成bean 字段 -->
44       <!--<ignoreColumn column="FRED" /> -->
45       <!-- 指定列的java数据类型 -->
46       <!--<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
47     
48   </context>
49 </generatorConfiguration>

    你只需要修改其中的数据库jar的地址,用户名,密码等。

   

    然后在写一个TXT,内容如下:(下次就不用写了)

    java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml - overwrite

    (在这个文件所在的文件夹里   shift + 右键   会看到一个  在此处打开命令窗口  然后复制进去 enter 即可

    看到success的字眼就说明成功了(反正我没有成功生成过)

 

  后来我找到了第二种方法,由于本农用myeclipse开发的,所以去网上搜索了,myeclipse的插件

 

    还是一样,下载资源:   http://download.csdn.net/detail/baalhuo/9526993

    然后像装SVN一样放进  myeclipse 安装目录的  ...\...\Myeclipse2014\dropins  下,直接解压进去就可以了。(如果已有文件了,就手动一个个放)

    重启 myeclipse 

    具体实现可看原文:   http://blog.csdn.net/baalhuo/article/details/51469675 

 

 

本文纯属个人学习笔记,如有雷同。算我抄你的。抱歉。  

mybatis generator

标签:使用   file   mysql   upd   try   sch   插件   注意   lips   

原文地址:http://www.cnblogs.com/D-Lin/p/6934904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!