mybaitis中mapper.xml条件查询" in " 语法

技术交流QQ群:796513209

使用场景描述如下

1、前端提交多个值到后台查询

<input name="codelist" id="codeid" maxlength="255" class=" form-control"/>

步骤一、本项目中后端用java对象接收前端的参数(前端input  name ="codelist" 与实体类接收属性名保持一致)

如:entity 中的属性

private List<String> codelist = Lists.newArrayList();  //存储前端传递的编码

步骤二、mapper接口层无需用注解,直接使用对象

步骤三、mapper.xml层代码如下

	<if test="codelist.size>0">
			AND a.code in
			<foreach collection="codelist" index="index" item="item" open="("
					 separator="," close=")">
					#{codelist[${index}]}
			</foreach>
	</if>

注!上面foreach中的值取法,取的是List,所以要用索引来取。

      conllection = "codelist"    codelist的值取得是list集合

发布了39 篇原创文章 · 获赞 8 · 访问量 3424

猜你喜欢

转载自blog.csdn.net/qq_41555278/article/details/103204840