mybatis一个select标签执行多个sql语句

第一步:首先在配置连接池的配置为:

d1.url=jdbc:mysql://xxx:3306/djtms?useUnicode=true&characterEncoding=UTF8&allowMultiQueries=true

第二步:

<resultMap id="longMap" type="Long"/>
<resultMap id="baseResultMap2" type="map"/>
<select id="getPage" resultMap="baseResultMap2,longMap" resultSets="items,count">
    select
    SQL_CALC_FOUND_ROWS
    <include refid="Base_Column_List"/>
    from t_area_open
    <where>
        <if test="queryParam  !=  null">
            <if test="queryParam.rowid != null">
                and `rowid` = #{ queryParam.rowid,jdbcType=INTEGER }
            </if>
            <if test="queryParam.fid != null">
                and fid = #{ queryParam.fid,jdbcType=VARCHAR }
            </if>
            <if test="queryParam.fprovinceName != null">
                and fprovince_name = #{ queryParam.fprovinceName,jdbcType=VARCHAR }
            </if>
            <if test="queryParam.fprovinceCode != null">
                and fprovince_code = #{ queryParam.fprovinceCode,jdbcType=TINYINT }
            </if>
            <if test="queryParam.fcityName != null">
                and fcity_name = #{ queryParam.fcityName,jdbcType=VARCHAR }
            </if>
            <if test="queryParam.fcityCode != null">
                and fcity_code = #{ queryParam.fcityCode,jdbcType=SMALLINT }
            </if>
            <if test="queryParam.fcountyName != null">
                and fcounty_name = #{ queryParam.fcountyName,jdbcType=VARCHAR }
            </if>
            <if test="queryParam.fcountyCode != null">
                and fcounty_code = #{ queryParam.fcountyCode,jdbcType=INTEGER }
            </if>
            <if test="queryParam.fstatus != null">
                and fstatus = #{ queryParam.fstatus,jdbcType=INTEGER }
            </if>
            <if test="queryParam.fcreatetime != null">
                and fcreatetime = #{ queryParam.fcreatetime,jdbcType=TIMESTAMP }
            </if>
            <if test="queryParam.fupdatetime != null">
                and fupdatetime = #{ queryParam.fupdatetime,jdbcType=TIMESTAMP }
            </if>
            <if test="queryParam.foperator != null">
                and foperator = #{ queryParam.foperator,jdbcType=VARCHAR }
            </if>
        </if>
    </where>
    limit
    #{offset},#{rows};
    SELECT FOUND_ROWS() AS COUNT;
</select>

Dao层接口是:

public Collection<Collection<?>> getPage(@Param("queryParam") T t, @Param("offset") int offset, @Param("rows") int rows);

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis 中,我们可以使用 collection 标签来实现一对多的查询。具体实现步骤如下: 1. 在主实体类中定义一个 List 类型的属性,用于存储多个从实体类对象。 2. 在主实体类对应的 Mapper.xml 文件中,使用 collection 标签来映射从实体类对象的集合。 3. 在 collection 标签中,使用 select 属性来指定查询从实体类对象的 SQL 语句,并使用 resultMap 属性来指定从实体类对象的映射关系。 例如,我们有一个 Order 实体类和一个 OrderItem 实体类,一个订单可以对应多个订单项。那么我们可以在 Order 实体类中定义一个 List<OrderItem> 类型的属性,然后在 Order 对应的 Mapper.xml 文件中使用 collection 标签来映射 OrderItem 对象的集合,具体代码如下: ``` <!-- OrderMapper.xml --> <select id="getOrderById" resultType="Order"> select * from orders where id = #{id} </select> <resultMap id="orderResultMap" type="Order"> <id property="id" column="id"/> <result property="orderNo" column="order_no"/> <collection property="orderItems" ofType="OrderItem" select="getOrderItemsByOrderId"/> </resultMap> <select id="getOrderItemsByOrderId" resultType="OrderItem"> select * from order_items where order_id = #{id} </select> ``` 在上面的代码中,我们定义了一个名为 orderResultMap 的 resultMap,其中使用了 collection 标签来映射 OrderItem 对象的集合。在 collection 标签中,我们使用 select 属性来指定查询 OrderItem 对象的 SQL 语句,并使用 ofType 属性来指定集合中元素的类型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值