方式一 :使用List作为参数
@Select({
"<script>",
"select",
"ip, content, note",
"from t_log",
"where note in",
"<foreach collection='notes' item='note' open='(' separator=',' close=')'>",
"#{note}",
"</foreach>",
"</script>"
})
List<TLog> getDataByNotes(@Param("notes") List<String> notes);
@Test
void xxx() {
List<String> list = new ArrayList<>();
list.add("p10");
list.add("p11");
list.add("p12");
List<TLog> tLogList = tLogMapper.getDataByNotes(list);
for (TLog log : tLogList) {
System.out.println("ip: "+log.getIp()+" ;content: "+log.getContent());
}
}
ip: 192.168.43.10 ;content: contentp10
ip: 192.168.43.11 ;content: contentp11
ip: 192.168.43.12 ;content: contentp12
方式二:使用数组传参
@Select({
"<script>",
"select",
"ip, content, note",
"from t_log",
"where note in",
"<foreach collection='notes' item='note' open='(' separator=',' close=')'>",
"#{note}",
"</foreach>",
"</script>"
})
List<TLog> getDataByNotes2(@Param("notes") String[] notes);
@Test
void xxx2() {
String[] arr = new String[]{"p10", "p11", "p12"};
List<TLog> tLogList = tLogMapper.getDataByNotes2(arr);
for (TLog log : tLogList) {
System.out.println("ip: "+log.getIp()+" ;content: "+log.getContent());
}
}
ip: 192.168.43.10 ;content: contentp10
ip: 192.168.43.11 ;content: contentp11
ip: 192.168.43.12 ;content: contentp12