Mybatis 注解開發傳入List 兩種方式接收方式 在IN場景中


1.在@Select中

@Select("<script>"
              + "SELECT IDFA FROM t_xxx WHERE IDFA IN "
              + "<foreach item='item' index='index' collection='strList' open='(' separator=',' close=')'>"
                  + "#{item}"
              + "</foreach>"
          + "</script>")
    @Results(value = { @Result(column = "user_name", property = "username") })
    public List<String> getXxxList(@Param("strList") List<String> strList);

說明:上述方式其實是一種注解完全代替xml的方法。

其中的foreach的collection直接寫成@param中的值即可。

摘自:https://www.cnblogs.com/java-zhao/p/5489269.html

2.將入參進行封裝,成(**,**,**,**,)

@Select("select access_pat_id from emr3.gp_doc_patients where access_pat_id in (#{apis}) and admission_time = (select max(admission_time) from emr3.gp_doc_patients where access_pat_id in (#{apis}))")
String getMaxTime(@Param("apis")String apis);
public static String indexForm(List<String> s){
String content="";
int i=0;
for (String ss:s){
i++;
if (i==s.size()){
content+=ss;
}else {
content+=ss+",";
}
}
return content;
}
該方法返回值就是入參apis


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM