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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大