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 ");