sql查询在pom.xml中的编写方式
1-模糊查询的常用3种方式
在userMapper.xml文件中新建sql标签
<!-- 通过姓名进行模糊查询 -->
<select id="selectByNameFuzzy" resultMap="BaseResultMap" parameterMap="java.util.Map">
select <include refid="Base_Column_List" /> from userinfo
<where>
/*方法一:使用bind标签对字段进行绑定,然后对绑定的字段进行使用*/
<if test="name != null">
<bind name="pattern" value="'%'+name+'%'"/>
name like #{pattern}
</if>
/*方法二:直接拼接字符串,如果"%#{name}%"这样拼接,会报错*/
<if test="name!=null">
name like "%"#{mame}"%"
</if>
/*方法三:使用concat(str1,str2)函数进行拼接*/
<if test="name!=null">
name like concat(concat("%",#{name}),"%")
</if>
</where>
</select>