Mybatis查询 模糊查询
Mybatis查询模糊查询
-
#{}安全 ${}存在sql注入
<select id="方法名" parameterType="参数类型" resultType="返回值类型">select * from 表名 where username like concat('%',#{注入的参数},'%')</select><select id="方法名" parameterType="参数类型" resultType="返回值类型">select * from 表名 where username like '%${参数}%'</select> -
需求:模糊地址或用户名查询
select * frmo users where username like '%小%' select * from users where address like '%市%' -
实现
<!--模糊用户名和地址查询 如果参数超过一个parameterType不写 List<Users> getByNameOrAddress(@Param("columnName") String columnName,@Param("ColumnValue") String ColumnValue) --> <select id="方法名" resultType="返回值类型"> select * from "表名" where ${ColumnValue} like concat('%',#{ColumnValue},'%') </select>

浙公网安备 33010602011771号