zb51500618 2016-06-08 07:38 采纳率: 83.3%
浏览 1288
已采纳

mybatis 级联查询一些问题

每次写mybatis 级联查询 就要写 几个 resultmap 一堆参数 ,sql也要把用到 的字段全部拼出来。

一直对mabatis 的用法不甚了解  到底用不用 这么麻烦


    <resultMap id="CommodityResult" type="com.ronhan.ctoc.model.Commodity">
    <id column="c_id" jdbcType="BIGINT" property="id" />
    <result column="c_skuid" jdbcType="VARCHAR" property="skuid" />
    <result column="c_state" jdbcType="TINYINT" property="state" />
    <result column="c_imageUrl" jdbcType="VARCHAR" property="imageUrl" />
    <result column="c_saleprice" jdbcType="DECIMAL" property="salePrice" />
</resultMap> 





















  <select id="showOfferList" parameterType="map"  resultMap="offerResult" >
    select  o.*,c.state as c_state , c.id as c_id ,c.skuid as c_skuid ,c.imageUrl as c_imageUrl,c.salePrice as c_saleprice,m.messages as m_messages
    from m_message m , o_offer o  left join c_commodity c on  o.commodity_id =c.id  left join o_offerhistroy oh  on o.id=oh.offer_id
    where 1=1  and oh.message_id= m.id 
    <if test="data.skuid!= null">
    and     c.skuid   LIKE '%${data.skuid}%'
    </if>
    <if test="data.status!=null">
    and     o.status =#{data.status}
    </if>
    <if test="data.startTime!=null">
        and o.createDate >#{data.startTime}
    </if>
    <if test="data.endTime!=null">
    and     o.createDate &lt; #{data.endTime}
    </if>

    limit ${page.start},${page.rowsPerPage}

就一个查询 写这么一大堆 ,  请问下 哪里可以优化一点吗?
  • 写回答

2条回答

  • Bug开发攻城狮 2016-06-08 07:59
    关注

    可以直接用hashMap作为resultMap

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作