记录一次需求为Mybatis的动态字段查询数据

需要根据用户选择字段来查询数据,类似Kibana搜索,如下:
用foreach来循环遍历所需字段:
foreach 基本语法:标签体内主要属性有item、index、collection、open、separator、close

item:集合中元素迭代时的别名
index:集合中元素迭代时的索引
open:表示以什么开始
separator:表示在每次进行迭代时的分隔符
close 常用语where语句中,表示以什么结束

 select
        <foreach collection="factorList" item="item" open=""
                 separator="," close="">
            ${
    
    item}
        </foreach>
 from mytable

猜你喜欢

转载自blog.csdn.net/Dengrz/article/details/111603829