MyBatis查询时按IN语句中的字段顺序排序的实现方式
发布时间
阅读量:
阅读量
分析
若查询结果的排列顺序不符合预期,可依据我们设定的特定顺序进行重新排序,相关SQL语句如下
SELECT * FROM tableName
WHERE fieldName in("Name1","Name2","Name3")
ORDER BY field(fieldName,"Name1","Name2","Name3")
解决
对应的MyBatis相关语句示例如下:
<select id = "myFunctionName" resultType="MyTypeName">
SELECT * FROM tableName
where fieldName in
<foreach collection="Names" item="id" index="index" open="(" close=")" separator=",">
${Name}
</foreach>
ORDER BY field(fieldName ,
<foreach collection="Names" item="id" in
全部评论 (0)
还没有任何评论哟~
