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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?