mybatis Example的Criteria用法:or與isNull詳解
mybatis Example的Criteria用法or與isNull
1.or
BaUserExample baUserExample = new BaUserExample();
Criteria criteria1 = baUserExample.createCriteria();
criteria1.andOrgIdEqualTo(“1”);
criteria1.andDeptIdEqualTo(“1”);
Criteria criteria2 = baUserExample.createCriteria();
criteria2.andUserNameEqualTo(“name”);
criteria2.andEmailLike("%test@%");
baUserExample.or(criteria2);
userMapper.countByExample(baUserExample);
2.isNull
為空要用isNull() 不要用equalTo(null) ,否則會(huì)報(bào)錯(cuò)。
mybatis Criteria的使用
查詢名字中帶有字母 r ,性別為男性(1)或者email中帶有數(shù)字1的人員信息
@Test
public void test1() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession openSession = sqlSessionFactory.openSession(true);
try {
EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
// List<Employee> selectAll = mapper.selectByExample(null);
EmployeeExample example = new EmployeeExample();
Criteria criteria = example.createCriteria();
criteria.andNameLike("%r%");
criteria.andGenderEqualTo("1");
Criteria criteria2 = example.createCriteria();
criteria2.andEmailLike("%1%");
example.or(criteria2);
List<Employee> select = mapper.selectByExample(example);
for(Employee employee :select) {
System.out.println(employee.getName()+employee.getEmail());
}
}finally {
openSession.close();
}
}
1.先實(shí)例化一個(gè)EmployeeExample對(duì)象
2.調(diào)用createCriteria()方法
3.查詢名字中帶有字母 r ,性別為男性(1)之間是and關(guān)系
criteria.andNameLike("%r%");
criteria.andGenderEqualTo("1");
4.查詢email中帶有數(shù)字1,并且已第一個(gè)criteria為基準(zhǔn)與其進(jìn)行or運(yùn)算
Criteria criteria2 = example.createCriteria();
criteria2.andEmailLike("%1%");
example.or(criteria2);
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java用單向環(huán)形鏈表來解決約瑟夫環(huán)Josepfu問題
如果把單鏈表的最后一個(gè)節(jié)點(diǎn)的指針指向鏈表頭部,而不是指向NULL,那么就構(gòu)成了一個(gè)單向循環(huán)鏈表,通俗講就是把尾節(jié)點(diǎn)的下一跳指向頭結(jié)點(diǎn)2021-10-10
JAVA實(shí)現(xiàn)心跳檢測(cè)(長(zhǎng)連接)
本文主要介紹了JAVA實(shí)現(xiàn)心跳檢測(cè)(長(zhǎng)連接),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
Spring Cloud Zipkin服務(wù)端追蹤服務(wù)
這篇文章主要介紹了Spring Cloud Zipkin服務(wù)端追蹤服務(wù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
Java filter中的chain.doFilter使用詳解
這篇文章主要介紹了Java filter中的chain.doFilter使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11
springboot報(bào)錯(cuò)Invalid?bound?statement?(not?found)的解決
本文主要介紹了springboot報(bào)錯(cuò)Invalid?bound?statement?(not?found)的解決,遇到這種問題通常是沒有配置好配置文件,下面就來具體介紹一下解決方法,感興趣的可以了解一下2025-03-03
vue 實(shí)現(xiàn)刪除對(duì)象的元素 delete
這篇文章主要介紹了vue 實(shí)現(xiàn)刪除對(duì)象的元素delete,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
java并發(fā)編程專題(九)----(JUC)淺析CyclicBarrier
這篇文章主要介紹了java CyclicBarrier的相關(guān)資料,文中示例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
RestClient?通過攔截器實(shí)現(xiàn)請(qǐng)求加密的示例
本文介紹了如何通過攔截器實(shí)現(xiàn)請(qǐng)求加密,并通過RestClient優(yōu)化了加密過程,傳統(tǒng)的加密方法依賴對(duì)象轉(zhuǎn)換和序列化處理,容易導(dǎo)致加密不一致或難以調(diào)試的問題,通過引入攔截器,可以直接操作請(qǐng)求體,避免了不必要的轉(zhuǎn)換步驟,確保加密過程與請(qǐng)求體完全一致,感興趣的朋友一起看看吧2025-02-02

