• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Loneliness Ends HUHU
热情坦诚
博客园    首页    新随笔    联系   管理    订阅  订阅
MyBatis Generator自动创建代码

        MyBatis Generator自动创建代码

    1.首先在eclipse上安装mybatis插件

        

     2.创建一个mavenWeb项目。

        

     3.在resource中写入一个xml,一定要与我得同名

       

 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     <properties resource="db.properties" />
 7     <context id="mysqlTables" targetRuntime="MyBatis3">
 8         <jdbcConnection driverClass="${jdbc.driver}"
 9             connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}" />
10         <!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
11         <javaTypeResolver>
12             <property name="forceBigDecimals" value="false" />
13         </javaTypeResolver>
14         <!--自动生成的实体的存放包路径 -->
15         <javaModelGenerator targetPackage="com.bw.pojo"
16             targetProject="src/main/java">
17             <property name="enableSubPackages" value="true" />
18             <property name="trimStrings" value="true" />
19         </javaModelGenerator>
20         <!--自动生成的*Mapper.xml文件存放路径 -->
21         <sqlMapGenerator targetPackage="com.bw.mapper"
22             targetProject="src/main/java">
23             <property name="enableSubPackages" value="true" />
24         </sqlMapGenerator>
25         <!--自动生成的*Mapper.java存放路径 -->
26         <javaClientGenerator type="XMLMAPPER"
27             targetPackage="com.bw.mapper" targetProject="src/main/java">
28             <property name="enableSubPackages" value="true" />
29         </javaClientGenerator>
30         <table tableName="user" domainObjectName="User"
31             enableCountByExample="false" enableUpdateByExample="false"
32             enableDeleteByExample="false" enableSelectByExample="false"
33             selectByExampleQueryId="false"></table>
34     </context>
35 </generatorConfiguration>

 1)此时table为我数据库中的表。

 2)这行是我写的数据库连接properties文件。你必须对应resource的位置写一个

       

 3)注意一定要创建你生成文件的位置,如com.**.pojo;com.**.mapper...等等

     4.注意,右键-->run As, --> mavenBuild ,在Goals中填 mybatis-generator:generate,直接点击run

        

 

      5.结果:

        

 

    不积小流无以成江海,不积硅步无以至千里。

posted on 2018-04-23 14:24  meiLinYa  阅读(196)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3