1.入参为对象的时候
List<AppUser> queryUser(AppUser user);
对应的sql
<!--模糊查询方式一 对象-->
<select id="queryUser" resultType="AppUser">
select
<include refid="dto" /> from USER where
<if test="phone != null and phone != ''">
<bind name="uphone" value="'%'+phone+'%'"/>
phone like #{uphone}
</if>
<if test="name != null and name != ''">
<bind name="uname" value="'%'+name+'%'"/>
and name like #{uname}
</if>
order by id desc
</select>
2.入参类型为Map,且没有加注解的时候,key 为phone、name
List<AppUser> queryUserBy2Map(HashMap<String,Object> mp);
对应的sql
<select id="queryUserBy2Map" parameterType="java.util.HashMap" resultType="AppUser" >
select
<include refid="dto" /> from USER where
<if test="phone != null and phone != ''">
<bind name="uphone" value="'%'+phone+'%'"/>
phone like #{uphone}
</if>
<if test="name != null and name != ''">
<bind name="uname" value="'%'+name+'%'"/>
and name like #{uname}
</if>
order by id desc
</select>
3.入参类型为Map,但是dao 层添加注解@Param,key为phone,name
List<AppUser> queryUserByMap(@Param("appUser") HashMap mp);
对应的sql
<!--模糊查询 map 方式,dao层加@Param("appUser") 注解-->
<select id="queryUserBy2Map" parameterType="java.util.HashMap" resultType="AppUser" >
select
<include refid="dto" /> from USER where
<if test="phone != null and phone != ''">
<bind name="uphone" value="'%'+phone+'%'"/>
phone like #{uphone}
</if>
<if test="name != null and name != ''">
<bind name="uname" value="'%'+name+'%'"/>
and name like #{uname}
</if>
order by id desc
</select>
--本文作者:【ngLee 】
--关于博文:如果有错误的地方,还请留言指正。如转载请注明出处!如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!