持久层接口的写法
List<?> selectBydeptNameandcreate_by(@Param("deptName") String dept_name,@Param("createBy") String create_by);
mapper.xml的写法
<select id="selectBydeptNameandcreate_by" resultMap="BaseResultMap">
select * from tbl_dept
<where>
<if test="deptName!=null"> dept_name like concat('%','${deptName}','%') </if>
<if test="createBy!=null"> and create_by like concat('%','${createBy}','%')</if>
</where>
</select>
从mapper看 有两个变量名,deptName,createBy,上面两个if语句分别表达的意思都是如果这个变量名里的值不为空则对某个属性进行like语句的模糊查询。
所以持久层必须用@Param定义这两个变量名保持一致,才能传参成功。最后返回的是一个list数据。