欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatis使用Example 生成 使用or()

程序员文章站 2024-03-02 13:39:04
...

@Override
public PageInfo agentListByNameAndPhone(Long userId,String plam, int pageNo, int pageSize) {

PageHelper.startPage(pageNo,pageSize);
TUserExample example=new TUserExample();
TUserExample.Criteria e=example.createCriteria();

if(plam!="" && plam!=null){
    e.andNickNameLike("%"+plam+"%");
    example.or().andPhoneLike("%"+plam+"%");
}
e.andCreateUserIdEqualTo(userId);
e.andDeleteEqualTo(UserType.DELETE_N.getCode());
//查询所有数据
List<TUser> list = uUserDAO.selectByExample(example);
//用PageInfo对结果进行包装
PageInfo<TUser> page = new PageInfo<TUser>(list);
return page;

}

在使用两个example.or(). like() 的时候出翔 criteria查询器 无效的时候
应该 example.or().andNickNameLike("%"+plam+"%");
example.or().andPhoneLike("%"+plam+"%");
改成
e.andNickNameLike("%"+plam+"%");
example.or().andPhoneLike("%"+plam+"%");

相关标签: mybatis example