mybatis中association和collection的column传入多个参数

mybatis中association和collection的column传入多个参数值

项目中在使用association和collection实现一对一和一对多关系时需要对关系中结果集进行筛选,如果使用懒加载模式,即联合使用select标签时,主sql和关系映射里的sql是分开的,查询参数传递成为问题。

mybatis文档:

property description
column 数据库的列名或者列标签别名。与传递给resultSet.getString(columnName)的参数名称相同。注意: 在处理组合键时,您可以使用column=“{prop1=col1,prop2=col2}”这样的语法,设置多个列名传入到嵌套查询语句。这就会把prop1和prop2设置到目标嵌套选择语句的参数对象中。

<resultMap type="com.zres.product.resmaster.portal.homePage.entity.ResTreeDetailEntity" id="leftTreeFirstMaps">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <id column="lngId" jdbcType="INTEGER" property="lngId"/>
        <collection property="children" ofType="com.zres.product.resmaster.portal.homePage.entity.ResTreeDetailEntity" select="queryLeftTreeById"
                    column="{id=id, lngId=lngId}">
        </collection>
    </resultMap>
    <select id="queryLeftTreeById" parameterType="map" resultMap="leftTreeFirstMaps">
        SELECT prt.id,
               prt.tree_id as treeId,
               prt.parent_id as parentId,
               prt.res_type_id as resTypeId,
               #{lngId} as lngId,
            <choose>
                <when test="lngId == -1">
                    prt.res_type as resName,
                </when>
                <otherwise>
                    FUN_GET_LNG_DESC(#{lngId},prt.id,prt.res_type,'PUB_RES_TREE_DETAIL',prt.env_domain_id) as resName,
                </otherwise>
            </choose>
               prt.icon as icon,
               prt.query_id as queryId,
               prt.role_id as roleId
        FROM pub_res_tree_detail prt
        WHERE prt.is_display = 1
          AND prt.parent_id = #{id}
          AND prt.is_resource = 2
    </select>

以前使用的都是一个参数注入, 后来增加了国际化之后需要使用多个类型, 可参考此法!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值