如何使用MyBatis批注将数组传递给IN子句

时间:2016-12-15 05:03:09

标签: spring-mvc mybatis spring-mybatis

我在使用Mybatis注释的IN子句的Code Snippet下面使用。我没有在执行时获得任何异常,但它返回0行。
请帮帮我。

@Select("SELECT A.* FROM RPRT_HDR A,SCHL_MSTR B WHERE A.SCHL_ID=B.SCHL_ID AND B.SCHOOL_NAME in (#{schools}) AND A.YR_MTH=#{ym}")
@Results(value={
@Result(property ="rprtKey",column="RPRT_KEY"),
@Result(property="reportImage",javaType = List.class,column ="rprtKey",many=@Many(select="getImages")),
@Result(property="reportQnAns",javaType = List.class,column ="rprtKey",many=@Many(select="getQuestionAnswer"))            
})        
List<ReportHeader> getReportdata(@Param("schools")String[] schools,@Param("ym")int yearmonth );

1 个答案:

答案 0 :(得分:0)

查询有效,因为Mybatis实际上将String数组发送到String,然后是有效的,但是只有匹配字符串的记录。 写:@Select("<script>SELECT A.* FROM RPRT_HDR A,SCHL_MSTR B WHERE A.SCHL_ID=B.SCHL_ID AND B.SCHOOL_NAME in (<foreach collection='schools' item='school' separator=', '>#{school}</foreach>) AND A.YR_MTH=#{ym}</script>")