根据条件查询用户,不区分条件大小写的吗。我查询条件是usersex = male 可是查出来的包括usersex = MALE 的
UsersMapper.xml
<!-- 根据用户给定条件查询-->
<select id="selectUsersByProperty" resultType="Users">
select * from users where 1=1
<if test="userid != 0">
and userid = #{userid}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
<if test="usersex != null and usersex != ''">
and usersex = #{usersex}
</if>
</select>
UsersMapper
List<Users> selectUsersByProperty(Users users);
UsersService
List<Users> findUsersByProperty(Users users);
UsersServiceImpl
/**
* 根据给定条件查询用户
* @param users
* @return
*/
@Override
public List<Users> findUsersByProperty(Users users) {
List<Users> list = null;
try{
SqlSession sqlSession = MybatisUtils.getSqlSession();
UsersMapper mapper = sqlSession.getMapper(UsersMapper.class);
list = mapper.selectUsersByProperty(users);
}catch (Exception e){
e.printStackTrace();
}finally {
MybatisUtils.closeSqlSession();
}
return list;
}
测试代码
public class FindUsersByPropertyTeset {
public static void main(String[] args) {
UsersServices usersServices = new UsersServicesImpl();
Users users = new Users();
users.setUsersex("male");
List<Users> list = usersServices.findUsersByProperty(users);
list.forEach(System.out::println);
}
}
运行结果
