美文网首页
mybatis example/criteria and or

mybatis example/criteria and or

作者: hisenyuan | 来源:发表于2018-03-14 19:44 被阅读0次

    秉着能不自己在xml里面写sql就不写的原则,今天新学习了一个姿势。
    利用 example 完成and or的查询

    public List<SmsCountry> queryCountryName() {
    SmsCountryExample example = new SmsCountryExample();
    Criteria criteria = example.createCriteria();
    //拼接and条件,如果有多个,可以直接在后面连着写
    criteria.andIdIsNotNull().andNameIsNotNull();
    //拼接or条件,如果有多个or必须这样写,连着写不行
    example.or().andIdEqualTo(1);
    example.or().andIdEqualTo(2);
    return smsCountryMapper.selectByExample(example);
    }

    相关文章

      网友评论

          本文标题:mybatis example/criteria and or

          本文链接:https://www.haomeiwen.com/subject/jurqqftx.html