/*
多条件查询方式一
*/public User findByIdAndUserName1(int id, String userName);
<!--多条件查询方式一
使用 #{arg0}-#{argn} 或者 #{param1}-#{paramn} 获取参数
--><selectid="findByIdAndUserName1"resultMap="userResultMap">
select * from user where id = #{arg0} and username = #{arg1}
</select>
<!--多条件查询方式二
使用注解,引入@Param() 注解获取参数
--><selectid="findByIdAndUserName2"resultMap="userResultMap">
select * from user where id = #{id} and username = #{username}
</select>
方式二
/*
多条件查询方式三
*/public User findByIdAndUserName3(User user);
<!--多条件查询方式三
使用pojo对象传递参数
大括号中的属性名需要与实体类中的属性名相同
--><selectid="findByIdAndUserName3"resultMap="userResultMap"parameterType="com.zhoufengbin.domain.User">
select * from user where id = #{idabc} and username = #{usernameabc}
</select>
<!--模糊查询:方式一
由于实体类中的属性名与关系表中的字段名不同,因此需要使用resultMap属性。
当传入参数为基本数据类型或String类型且只传入一个参数,#{}中的值可以任意填写。
#{} 在mybatis中是占位符,引用参数值得时候会自动添加单引号。
--><selectid="findByUsername1"resultMap="userResultMap"parameterType="string">
select * from user where username like #{username}
</select>
<!--模糊查询:方式二
parameterType 当传入参数为基本数据类型或String类型且只传入一个参数,${}中的值只能填写为value。
${}: sql原样拼接,需要手动添加单引号。
--><selectid="findByUsername2"resultMap="userResultMap"parameterType="string">
select * from user where username like '${value}'
</select>