关于mybats一对一查询(个人的笔记本)

3 篇文章 0 订阅
2 篇文章 0 订阅

一个<resultMap>

<resultMap id="BaseResultMap" type="com.commnetsoft.admin.model.cav.LogCrash">    
       <id column="ID" property="id" jdbcType="INTEGER" />
       <result column="DEVICEID" property="deviceid" jdbcType="VARCHAR" />
       <result column="DEVICEBRAND" property="devicebrand" jdbcType="VARCHAR" />
       <result column="DEVICETYPE" property="devicetype" jdbcType="VARCHAR" />
       <result column="OS" property="os" jdbcType="VARCHAR" />
       <result column="VERSIONID" property="versionid" jdbcType="INTEGER" />
       <result column="FILEID" property="fileid" jdbcType="INTEGER" />
       <result column="CREATETIME" property="createtime" jdbcType="TIMESTAMP" />
        <association property="appVersion" javaType="com.commnetsoft.admin.model.cav.AppVersion"   >
         <id column="ID" property="id" jdbcType="INTEGER" />
         <result column="TAG" property="tag" jdbcType="VARCHAR" />
         <result column="CODE" property="code" jdbcType="INTEGER" />
          <result column="NAME" property="name" jdbcType="VARCHAR" />
        </association>

   </resultMap>

一个查询

<select id="select" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select
             *
        from cav_log_crash c
          left join cav_appversion t
        on c.VERSIONID = t.id   
        <include refid="Base_Where_Clause" />

    </select>

设置查询条件

<sql id="Base_Where_Clause">
        <where>
           <trim prefixOverrides="and">
              
               <if test="id != null"> and id =#{id}</if>
                <if test="deviceid != null"> and deviceid = #{deviceid}</if>
                <if test="devicebrand != null"> and devicebrand = #{devicebrand}</if>
                <if test="devicetype != null"> and devicetype = #{devicetype}</if>
                <if test="os != null"> and os = #{os}</if>
                <if test="versionid != null"> and versionid = #{versionid}</if>
                <if test="fileid != null"> and fileid = #{fileid}</if>
                <if test="createtime != null"> and createtime = #{createtime}</if>
                <if test="name!= null"> and name = #{name}</if>
                 <if test="deviceidLike != null"> and deviceid like CONCAT("%",#{deviceidLike},"%")</if>
                <!-- <if test="nameLike != null">and t.name =#{nameLike}</if> -->
                 <if test="code != null">and t.code = #{codeLike}</if>
                <if test="codeLike != null">and t.code like CONCAT("%",#{codeLike},"%")</if>
           </trim>
          <!-- or 查询 主要用与数据权限控制 -->
              <if test="dataLimit != null">
                <foreach item="item" index="index" collection="dataLimit" open="and (" separator=" or " close=")">  
                  ${item}
                </foreach>
            </if>
        </where>
         <if test="sorting != null">order by c.${sorting}</if>

    </sql>


最后别忘记在主表的实体类中关联一下字表的实体类 例如 private AppVersion appVersion




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值