gpt4 book ai didi

java - 使用动态别名准备 ibatis 查询

转载 作者:太空宇宙 更新时间:2023-11-04 06:43:58 27 4
gpt4 key购买 nike

我需要使用 ibatis 创建一个查询,如下所示:

SELECT code,name,info0,info1,.... FROM TABLENAME;

info0,info1,....可以是任何数字,我需要动态准备。

code,name,info0,info1....都是别名。

IBATIS 查询

<select id="getReferenceDataListByReferenceMasterInfo"
parameterType="com.util.ReferenceMetaData" resultMap="refdatalist-result">

SELECT code,name,

<if test="infoNameList != null">
<foreach item="item" index="index" separator="," collection="infoNameList">
#{'info'${index}}
</foreach>
</if>

FROM
(
SELECT
trim(${codeColumnName}) as code,

<choose>
<when test="nameColumnName != null">
${nameColumnName} as name,
</when>
<otherwise>
null as name,
</otherwise>
</choose>
<choose>
<when test="infoNameList != null">
<foreach item="item" index="index" collection="infoNameList">
${item} as info${index},
</foreach>
</when>
</choose>
row_number() over (order by ${codeColumnName}) as ROWNUM

FROM UREF.${tableName}

)
</select>

如果我们将别名显式指定为:

,则上述查询可以完美运行:
SELECT code,name,info0,info1,info2 FROM (...

最佳答案

得到答案了......

代码如下所示,

<if test="infoNameList != null">
<foreach item="item" index="index" separator="," collection="infoNameList">
info${index}
</foreach>
</if>

关于java - 使用动态别名准备 ibatis 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24283198/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com