表结构

需要查询几种虫子对应的应对措施。
sql
select solution_key, solution_content from zz_pest_solution where solution_type = 0 and and solution_key IN ("蜜蜂","象鼻虫","蝗虫");
mapper文件

需要注意@Param注解,告诉xml你传入的参数名称。
否则会报错
xml文件

foreach写法
<select id="getSolutionByPestName" resultType="java.util.Map">
select solution_key, solution_content from zz_pest_solution where solution_type = 0
<if test="pestName != null and pestName!=''">
and solution_key IN
<foreach item="pest" collection="pestName" open="(" separator="," close=")">
#{pest}
</foreach>
</if>
</select>
查询成功
版权声明:本文为weixin_43916065原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。