mybatis 之引入多个model

配置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>
时间: 2024-08-08 13:48:05

mybatis 之引入多个model的相关文章

spring和mybatis集成,自动生成model、mapper,增加mybatis分页功能

软件简介 Spring是一个流行的控制反转(IoC)和面向切面(AOP)的容器框架,在java webapp开发中使用广泛.http://projects.spring.io/spring-framework/ MyBatis是一个基于Java的数据持久层框架,其原名是iBatis,在升级到3.0版本后,更名为MyBatis.https://github.com/mybatis/mybatis-3/ MyBatis Generator是一个MyBatis的代码生成器,通过配置,可自动生成数据操作

05 MyBatis的引入和说明

1 下载地址 http://qunying2.jb51.net:81/201905/tools/mybatis_jb51.rar 2 引入MyBatis的jar包及依赖包 在粘贴到lib下builde Path即可. 内部包说明 3 在src下新建全局配置文件 配置文件即xml文件,主要用于存储连接数据库的四个变量(driver,url,user,password). 配置文件名没有要求(比如MyBatis.xml),地址也是. 3.1 在全局配置文件中引入DTD或schema(不导就没有提示(

mybatis generator自动生成Mapper文件和Model

使用Mybatis generator可以根据数据库表生成mybatis对应的Mapper和Model,生成的Example可以满足一般的单表操作,使用Mybatis的注释,利用@mbggenerated可以在下次生成的时候将自动生成的代码覆盖掉,对于手工加入的查询不影响(需要使用的eclipse的插件,intellij目前不存在类似的插件),在使用intellij中,可以使用免费的mybatis插件,可以在Mapper类中快速定位到对应的xml中,非常有利于sql查看: Mybatis配置:

idea的maven项目下spring与mybatis整合

两周前学习mybatis框架,参考了网上多位大神的博客,但因为各种原因(不解释)总是没法成功搭建环境并运行项目.周末花了点时间阅读了文档并整理之前琐碎的内容,解决掉之前遇到的问题.现将整合环境的关键步骤整理成学习手记一篇. 文章只提取了整合环境的主体过程,没有太深入的解析其中内容,若想深入学习mybaits,请自行阅读文档.源码,或参看网上其他大神的博客,本人菜鸟一只,只是做做学习笔记(ps:吃货请直接拖到底部). 1.导入spring核心包.spring测试包.mybatis核心包.mysql

springboot+mybatis+druid数据库连接池

参考博客https://blog.csdn.net/liuxiao723846/article/details/80456025 1.先在pom.xml中引入druid依赖包 <!-- 连接池 --> <!-- Druid 数据连接池依赖 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>

Spring Boot (七): Mybatis极简配置

Spring Boot (七): Mybatis极简配置 1. 前言 ORM 框架的目的是简化编程中的数据库操作,经过这么多年的发展,基本上活到现在的就剩下两家了,一个是宣称可以不用写 SQL 的 Hibernate ,一个是对 SQL 非常友好的 Mybaties ,,两者各有特点,在企业级系统开发中可以根据需求灵活使用.发现一个有趣的现象:传统企业大都喜欢使用 Hibernate ,互联网行业通常使用 Mybatis . Hibernate 特点就是所有的 SQL 都用 Java 代码来生成

从头开始搭建一个mybatis+postgresql平台

     最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮助我们做了很多实用的事情,大多数情况下我们需要在原生态mybatis上加工的想法它基本上都已经有很好的实现,这篇将分享安装postgresql,配置tk.mybatis的详细步骤以及在这过程中可能遇到的一些小问题. 安装postgresql,执行下面的命令就可以安装了: apt-get update && apt-get install

mybatis+postgresql平台

mybatis+postgresql平台        最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮助我们做了很多实用的事情,大多数情况下我们需要在原生态mybatis上加工的想法它基本上都已经有很好的实现,这篇将分享安装postgresql,配置tk.mybatis的详细步骤以及在这过程中可能遇到的一些小问题. 安装postgresql,执行下面的命令就可以安装了: apt-get update

generator自动生成mybatis配置和类信息

generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包.        网址:http://code.google.com/p/mybatis/downloads/list?can=3&q=Product%3DGenerator,下载mybatis-generator-core-1.3.2-bundle.zip,解压        找到lib下的需要jar包. 2.编写genertor的xml文