zoukankan      html  css  js  c++  java
  • mybatis-generator

    需要在maven的plugins标签配置plugin。但是不能配置在<pluginManagement>标签内

    1       <plugin>
    2         <groupId>org.mybatis.generator</groupId>
    3         <artifactId>mybatis-generator-maven-plugin</artifactId>
    4         <version>1.3.2</version>
    5         <configuration>
    6           <verbose>true</verbose>
    7           <overwrite>true</overwrite>
    8         </configuration>
    9       </plugin>

      自动将表生成对应的实体类、DAO接口和对应的sqlMapper.xml文件。前提要配置generatorConfig.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 
      6 <generatorConfiguration>
      7     <!--导入属性配置-->
      8     <properties resource="datasource.properties"/>
      9 
     10     <!--指定特定数据库的jdbc驱动jar包的位置-->
     11     <classPathEntry location="${db.driverLocation}"/>
     12 
     13     <context id="default" targetRuntime="MyBatis3">
     14 
     15         <!-- optional,旨在创建class时,对注释进行控制 -->
     16         <commentGenerator>
     17             <property name="suppressDate" value="true"/>
     18             <property name="suppressAllComments" value="true"/>
     19         </commentGenerator>
     20 
     21         <!--jdbc的数据库连接 -->
     22         <jdbcConnection
     23                 driverClass="${db.driverClassName}"
     24                 connectionURL="${db.url}"
     25                 userId="${db.username}"
     26                 password="${db.password}">
     27         </jdbcConnection>
     28 
     29 
     30         <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
     31         <javaTypeResolver>
     32             <property name="forceBigDecimals" value="false"/>
     33         </javaTypeResolver>
     34 
     35 
     36         <!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
     37             targetPackage     指定生成的model生成所在的包名
     38             targetProject     指定在该项目下所在的路径
     39         -->
     40         <!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".srcmainjava">-->
     41         <javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
     42             <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
     43             <property name="enableSubPackages" value="false"/>
     44             <!-- 是否对model添加 构造函数 -->
     45             <property name="constructorBased" value="true"/>
     46             <!-- 是否对类CHAR类型的列的数据进行trim操作 -->
     47             <property name="trimStrings" value="true"/>
     48             <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
     49             <property name="immutable" value="false"/>
     50         </javaModelGenerator>
     51 
     52         <!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
     53         <!--<sqlMapGenerator targetPackage="mappers" targetProject=".srcmain
    esources">-->
     54         <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
     55             <property name="enableSubPackages" value="false"/>
     56         </sqlMapGenerator>
     57 
     58         <!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
     59                 type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
     60                 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
     61                 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
     62         -->
     63 
     64         <!-- targetPackage:mapper接口dao生成的位置 -->
     65         <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".srcmainjava">-->
     66         <javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
     67             <!-- enableSubPackages:是否让schema作为包的后缀 -->
     68             <property name="enableSubPackages" value="false" />
     69         </javaClientGenerator>
     70 
     71 
     72         <table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false"
     73                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     74                selectByExampleQueryId="false"/>
     75         <table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false"
     76                enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
     77         <table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false"
     78                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     79                selectByExampleQueryId="false"/>
     80         <table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false"
     81                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     82                selectByExampleQueryId="false"/>
     83         <table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false"
     84                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     85                selectByExampleQueryId="false"/>
     86         <table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false"
     87                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     88                selectByExampleQueryId="false"/>
     89         <table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false"
     90                enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
     91                selectByExampleQueryId="false"/>
     92         <table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
     93             <columnOverride column="detail" jdbcType="VARCHAR" />
     94             <columnOverride column="sub_images" jdbcType="VARCHAR" />
     95         </table>
     96         <table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false"
     97                enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
     98 
     99 
    100         <!-- geelynote mybatis插件的搭建 -->
    101     </context>
    102 </generatorConfiguration>
  • 相关阅读:
    从源代码解释Android事件分发机制
    怎样让oracle实验本在不做实验时性能提升——win7下举例
    could only be replicated to 0 nodes, instead of 1
    虚拟机和主机ping不通解决的方法
    ZOJ3623:Battle Ships(全然背包)
    Android 网络编程之---HttpClient 与 HttpURLConnection 共用cookie
    注冊成为Windows Phone开发人员而且解锁Windows Phone 8.1手机
    sharding-method首页、文档和下载
    rootsongjc/kubernetes-handbook: Kubernetes中文指南/实践手册
    如何基于K8S打造轻量级PaaS平台
  • 原文地址:https://www.cnblogs.com/elian91/p/15359955.html
Copyright © 2011-2022 走看看