mybatis的实现泛型查询数据

List<User> selectUserListByType(Map map);

以这个方法为例:其中参数map的键里面存储的是根据什么类型代码查询假设三个值(100,101,102),而值是list类型的数组,或者一些String,那么相对应的xml的文件实现的话就类似下面的这些代码(这个只是给我做记忆的不为了其他):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mapper.UserMapper">
	<!--其他的类型UserResultMap以及sql这些省略-->
	<select id="selectUserListByType" resultMap="UserResultMap"
		parameterType="Map">
		SELECT
		<include refid="Base_Column_List" />
		FROM account,profile
		<where>
			<!-- 下面if判断中的type为查询的类型, 其中100为根据id集合查询, 101为根据profile的name属性模糊查询, 102为根据根据手机号(account的username属性,profile的phone属性)查询, 
				目前需求只是单个手机号,不过也适用 -->
			<if test="type==100">
				account.id IN (
				<foreach item="p" collection="params" separator=",">
					#{p}
				</foreach>
				)
			</if>
			<if test="type==101">
				profile.name like '%${params}%'
			</if>
			<if test="type==102">
				account.username IN (
				<foreach item="p" collection="params" separator=",">
					#{p}
				</foreach>
				)
			</if>
		</where>
		AND account.id=profile.uid;
	</select>
</mapper>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值