1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" > 3 <generatorConfiguration> 4 <!-- 引入配置文件 --> 5 <properties resource="init.properties"/> 6 7 <!-- 指定数据连接驱动jar地址 --> 8 <classPathEntry location="${classPath}" /> 9 10 <!-- 一个数据库一个context --> 11 <context id="infoGuardian"> 12 <!-- 注释 --> 13 <commentGenerator > 14 <property name="suppressAllComments" value="false"/><!-- 是否取消注释 --> 15 <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳--> 16 </commentGenerator> 17 18 <!-- jdbc连接 --> 19 <jdbcConnection driverClass="${jdbc_driver}" 20 connectionURL="${jdbc_url}" userId="${jdbc_user}" 21 password="${jdbc_password}" /> 22 23 <!-- 类型转换 --> 24 <javaTypeResolver> 25 <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --> 26 <property name="forceBigDecimals" value="false"/> 27 </javaTypeResolver> 28 29 <!-- 生成实体类地址 --> 30 <javaModelGenerator targetPackage="com.oop.eksp.user.model" 31 targetProject="${project}" > 32 <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> 33 <property name="enableSubPackages" value="false"/> 34 <!-- 是否针对string类型的字段在set的时候进行trim调用 --> 35 <property name="trimStrings" value="true"/> 36 </javaModelGenerator> 37 38 <!-- 生成mapxml文件 --> 39 <sqlMapGenerator targetPackage="com.oop.eksp.user.data" 40 targetProject="${project}" > 41 <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> 42 <property name="enableSubPackages" value="false" /> 43 </sqlMapGenerator> 44 45 <!-- 生成mapxml对应client,也就是接口dao --> 46 <javaClientGenerator targetPackage="com.oop.eksp.user.data" 47 targetProject="${project}" type="XMLMAPPER" > 48 <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> 49 <property name="enableSubPackages" value="false" /> 50 </javaClientGenerator> 51 52 <!-- 配置表信息 --> 53 <table schema="${jdbc_user}" tableName="s_user" 54 domainObjectName="UserEntity" enableCountByExample="false" 55 enableDeleteByExample="false" enableSelectByExample="false" 56 enableUpdateByExample="false"> 57 <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 58 是否生成 example类 --> 59 60 <!-- 忽略列,不生成bean 字段 --> 61 <ignoreColumn column="FRED" /> 62 <!-- 指定列的java数据类型 --> 63 <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> 64 </table> 65 66 </context> 67 </generatorConfiguration>
自动生成Mappler.xml 和dao接口。基本的查询都有,需要一些拼接
例如:
1 <select id = "selectShopCartByCustomerId" parameterType="com.hebg3.mobiledealer.modules.storeorder.entity.ShopCartExample" resultMap="BaseResultMap"> 2 select 3 <if test="distinct"> 4 distinct 5 </if> 6 <include refid="Base_Column_List" /> 7 from t_shop_cart 8 <if test="_parameter != null"> 9 <include refid="Example_Where_Clause" /> 10 </if> 11 <if test="orderByClause != null"> 12 order by ${orderByClause} 13 </if> 14 15 16 </select>
1 ShopCartExample shopCartExample = new ShopCartExample(); 2 3 shopCartExample.or().andTCustomerIdEqualTo(tCustomerId); 4 shopCartExample.setOrderByClause("t_dealer_id,create_date ");
1 ShopCartExample shopCartExample = new ShopCartExample(); 2 3 shopCartExample.or().andTCustomerIdEqualTo(tCustomerId); 4 shopCartExample.setOrderByClause("t_dealer_id,create_date ");