mybatis 之引入多個model
阿新 • • 發佈:2017-08-21
tar integer row 根據 引入 upd edi .org 關聯
配置hessian:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- 對在此配置文件下的所有cache 進行全局性開/關設置 true,false --> <setting name="cacheEnabled" value="true" /> <!-- 全局性設置懶加載。如果設為‘false’,則所有相關聯的都會被初始化加載 true,false --> <setting name="lazyLoadingEnabled" value="true" /> <!-- 當設置為‘true’的時候,懶加載的對象可能被任何懶屬性全部加載。否則,每個屬性都按需加載 true,false --> <setting name="aggressiveLazyLoading" value="true" /> <!-- 允許和不允許單條語句返回多個數據集(取決於驅動需求),默認true --> <setting name="multipleResultSetsEnabled" value="true" /> <!-- 使用列標簽代替列名稱。不同的驅動器有不同的作法。參考一下驅動器文檔,或者用這兩個不同的選項進行測試一下 true,false --> <setting name="useColumnLabel"value="true" /> <!-- 允許JDBC 生成主鍵。需要驅動器支持。如果設為了true,這個設置將強制使用被生成的主鍵,有一些驅動器不兼容不過仍然可以執行 true,false --> <setting name="useGeneratedKeys" value="false" /> <!-- 指定MyBatis 是否並且如何來自動映射數據表字段與對象的屬性。PARTIAL將只自動映射簡單的,沒有嵌套的結果。FULL將自動映射所有復雜的結果 NONE,PARTIAL,FULL --> <setting name="autoMappingBehavior" value="PARTIAL" /> <!-- 配置和設定執行器,SIMPLE執行器執行其它語句。REUSE執行器可能重復使用prepared statements語句,BATCH執行器可以重復執行語句和批量更新 SIMPLE,REUSE,BATCH --> <setting name="defaultExecutorType" value="REUSE" /> <!-- 設置一個時限,以決定讓驅動器等待數據庫回應的多長時間為超時 --> <setting name="defaultStatementTimeout" value="25000" /> </settings> <!-- 引入Model 對象 --> <typeAliases> <typeAlias alias="HwgActivityInfo" type="com.j1.hwg.model.HwgActivityInfo" /> <typeAlias alias="HwgSelectGoods" type="com.j1.hwg.model.HwgSelectGoods" /> <typeAlias alias="HwgHotBrand" type="com.j1.hwg.model.HwgHotBrand" /> <typeAlias alias="HwgCategoryImage" type="com.j1.hwg.model.HwgCategoryImage" /> <typeAlias alias="HwgCategoryProduct" type="com.j1.hwg.model.HwgProduct" /> <typeAlias alias="HwgKeyword" type="com.j1.hwg.model.HwgKeyword" /> <typeAlias alias="HwgProductEvaluation" type="com.j1.hwg.model.HwgProductEvaluation" /> <typeAlias alias="HwgProductSaleLimit" type="com.j1.hwg.model.HwgProductSaleLimit" /> <typeAlias alias="HwgCatalogBrand" type="com.j1.hwg.model.HwgCatalogBrand" /> </typeAliases> </configuration>
或者是Model的全路徑:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.j1.soa.resource.hwg.dao.oracle.HwgCatalogBrandMapper"> <resultMap id="HwgCatalogBrandMap" type="HwgCatalogBrand"> <result column="CATALOG_BRAND_ID" property="catalogBrandId" /> <result column="PRO_CATALOG_ID" property="proCatalogId" /> <result column="PRODUCT_BRAND_NAME" property="productBrandName" /> <result column="PRODUCT_BRAND_IMG" property="productBrandImg" /> <result column="PRODUCT_BRAND_URL" property="productBrandUrl" /> <result column="PRO_CATALOG_NAME" property="proCatalogName" /> <result column="CATALOG_BRAND_ORDER" property="catalogBrandOrder" /> </resultMap> <resultMap id="hwgCategoryMap" type="com.j1.hwg.model.HwgCategory"> <result column="PRO_CATALOG_ID" property="categoryId"/> <result column="PRO_CATALOG_NAME" property="categoryName"/> </resultMap> <!-- 用於分頁查詢的頭部 --> <sql id="be_fy"> select * from (select row_.*, rownum rownum_ from ( </sql> <!-- 用於分頁的尾部 --> <sql id="ed_fy"> ) row_ where 1=1 <if test="endRow != null"> <![CDATA[ and rownum <= #{endRow} ]]> </if> ) where 1=1 <if test="startRow != null"> <![CDATA[ and rownum_ >= #{startRow} ]]> </if> </sql> <!-- 查詢 --> <select id="queryHwgCatalogBrandPages" resultMap="HwgCatalogBrandMap" parameterType="HwgCatalogBrand"> <include refid="be_fy" /> select t.catalog_brand_id, t.pro_catalog_id, t.product_brand_name, t.product_brand_img, t.product_brand_url, l.pro_catalog_name, t.catalog_brand_order from hwg_catalog_brand t inner join product_catalog l on l.pro_catalog_id =t.pro_catalog_id <where> t.is_delete = ‘N‘ <if test="productBrandName != null and productBrandName != ‘‘"> and t.PRODUCT_BRAND_NAME like ‘%‘||#{productBrandName}||‘%‘ </if> <if test="proCatalogId != null and proCatalogId != 0"> and t.PRO_CATALOG_ID =#{proCatalogId} </if> </where> order by t.ADD_TIME desc <include refid="ed_fy" /> </select> <!-- 查詢總數量 --> <select id="getHwgCatalogBrandCount" resultType="java.lang.Integer" parameterType="HwgCatalogBrand"> select count(1) from hwg_catalog_brand t <where> t.is_delete = ‘N‘ <if test="productBrandName != null and productBrandName != ‘‘"> and t.PRODUCT_BRAND_NAME like ‘%‘||#{productBrandName}||‘%‘ </if> <if test="proCatalogId != null and proCatalogId != 0 "> and t.PRO_CATALOG_ID =#{proCatalogId} </if> </where> </select> <!-- 根據主鍵查詢 --> <select id="getHwgCatalogBrandById" resultMap="HwgCatalogBrandMap" parameterType="java.lang.Long"> select t.catalog_brand_id, t.pro_catalog_id, t.product_brand_name, t.product_brand_img, t.product_brand_url, t.catalog_brand_order from hwg_catalog_brand t where t.catalog_brand_id = #{catalogBrandId} </select> <!-- 根據分類ID查詢 --> <select id="getHwgCatalogBrandByCatalogId" resultMap="HwgCatalogBrandMap" parameterType="java.lang.Long"> select t.catalog_brand_id, t.pro_catalog_id, t.product_brand_name, t.product_brand_img, t.product_brand_url, t.catalog_brand_order from hwg_catalog_brand t where t.PRO_CATALOG_ID = #{proCatalogId} AND t.is_delete=‘N‘ ORDER BY t.CATALOG_BRAND_ORDER </select> <!-- 保存 --> <insert id="save" parameterType="HwgCatalogBrand"> <selectKey resultType="java.lang.Long" keyProperty="catalogBrandId" order="BEFORE"> SELECT HWG_CATALOG_BRAND_ID_SEQ.nextval from dual </selectKey> insert into HWG_CATALOG_BRAND <trim prefix="(" suffix=")" suffixOverrides=","> CATALOG_BRAND_ID, <if test="proCatalogId != null"> PRO_CATALOG_ID, </if> <if test="productBrandName != null"> PRODUCT_BRAND_NAME, </if> <if test="productBrandImg != null"> PRODUCT_BRAND_IMG, </if> <if test="productBrandUrl != null"> PRODUCT_BRAND_URL, </if> <if test="catalogBrandOrder != null"> catalog_brand_order, </if> <if test="addUserId != null"> ADD_USER_ID, </if> <if test="editTime != null"> EDIT_TIME, </if> <if test="addTime != null"> ADD_TIME, </if> <if test="editUserId != null"> EDIT_USER_ID, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> #{catalogBrandId,jdbcType=NUMERIC}, <if test="proCatalogId != null"> #{proCatalogId,jdbcType=NUMERIC}, </if> <if test="productBrandName != null"> #{productBrandName,jdbcType=VARCHAR}, </if> <if test="productBrandImg != null"> #{productBrandImg,jdbcType=VARCHAR}, </if> <if test="productBrandUrl != null"> #{productBrandUrl,jdbcType=VARCHAR}, </if> <if test="catalogBrandOrder != null"> #{catalogBrandOrder,jdbcType=NUMERIC}, </if> <if test="addUserId != null"> #{addUserId,jdbcType=NUMERIC}, </if> <if test="editTime != null"> #{editTime,jdbcType=VARCHAR}, </if> <if test="addTime != null"> #{addTime,jdbcType=VARCHAR}, </if> <if test="editUserId != null"> #{editUserId,jdbcType=NUMERIC}, </if> </trim> </insert> <!-- 修改 --> <update id="update" parameterType="HwgCatalogBrand"> update HWG_CATALOG_BRAND <set> <if test="proCatalogId != null and proCatalogId != ‘‘"> PRO_CATALOG_ID =#{proCatalogId,jdbcType=NUMERIC}, </if> <if test="productBrandName != null and productBrandName != ‘‘"> PRODUCT_BRAND_NAME = #{productBrandName,jdbcType=VARCHAR}, </if> <if test="productBrandImg != null and productBrandImg != ‘‘"> PRODUCT_BRAND_IMG = #{productBrandImg,jdbcType=VARCHAR}, </if> <if test="productBrandUrl != null and productBrandUrl != ‘‘"> PRODUCT_BRAND_URL = #{productBrandUrl,jdbcType=VARCHAR}, </if> <if test="catalogBrandOrder != null and catalogBrandOrder != ‘‘"> CATALOG_BRAND_ORDER = #{catalogBrandOrder,jdbcType=NUMERIC}, </if> <if test="addUserId != null and addUserId != ‘‘"> ADD_USER_ID = #{addUserId,jdbcType=NUMERIC}, </if> <if test="addTime != null and addTime != ‘‘"> ADD_TIME = #{addTime,jdbcType=VARCHAR}, </if> <if test="editUserId != null and editUserId != ‘‘"> EDIT_USER_ID = #{editUserId,jdbcType=NUMERIC}, </if> <if test="editTime != null and editTime != ‘‘"> EDIT_TIME = #{editTime,jdbcType=VARCHAR}, </if> <if test="isDelete != null and isDelete != ‘‘"> IS_DELETE = #{isDelete,jdbcType=VARCHAR} </if> </set> where catalog_brand_id = #{catalogBrandId,jdbcType=NUMERIC} </update> <!-- 刪除 --> <update id="delete" parameterType="java.util.List"> update HWG_CATALOG_BRAND set IS_DELETE=‘Y‘ where catalog_brand_id in <foreach item="item" collection="list" separator="," open="(" close=")"> #{item, jdbcType=NUMERIC} </foreach> </update> <select id="queryCatalog" resultMap="hwgCategoryMap" parameterType="java.lang.String"> select c.PRO_CATALOG_ID ,c.PRO_CATALOG_NAME from PRODUCT_CATALOG c where c.PRO_PARENT_CATALOG IN (select c.PRO_CATALOG_ID from PRODUCT_CATALOG c,PRODUCT_CATALOG_AUTH a where a.PRO_CATALOG_ID=c.PRO_CATALOG_ID and c.IS_DELETE=‘N‘ and c.PRO_CATALOG_LEVEL=0 and a.AUTH_TYPE=#{value}) </select> <!-- 查詢所有樓層 --> <select id="getAbroadCategoryInfo" resultType="com.j1.hwg.webmodel.AbroadCategoryInfo" > select hc.category_id as categoryId, hc.category_name as categoryName from hwg_category hc where hc.is_delete=‘N‘ order by hc.category_order </select> </mapper>
mybatis 之引入多個model