当前位置:网站首页>Tkmapper uses weekend splicing conditions to query conditions
Tkmapper uses weekend splicing conditions to query conditions
2022-07-16 06:06:00 【Kuo-Teng】
tkMapper The use of Weekend Join conditions to query conditions
0. introduce
We use it here StudentInfo Entity classes :
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StudentInfo {
@Id
private Long id;
/** * full name */
private String name;
/** * cell-phone number */
private String mobile;
/** * Student number */
private String studentId;
/** * Class number */
private String classId;
/** * Creation time */
private Date ctime;
/** * Update time */
private Date mtime;
/** * Delete logo 0: Not delete 1: Delete */
private Integer deleted_status;
}
1. andEqualTo
Use andEqualTo sentence , It is equivalent to using where Field name = Certain value Of SQL sentence
If we want to inquire about the class number 12345678 Of the students , It can be written like this :
Weekend<StudentInfo> weekend = Weekend.of(StudentInfo.class);
WeekendCriteria<StudentInfo, Object> weekendCriteria = weekend.weekendCriteria();
weekendCriteria.andEqualTo(StudentInfo::getClassId, "12345678");
weekendCriteria.andEqualTo(StudentInfo::getdeletedStatus, 0);
List<StudentInfo> infoList = studentInfoMapper.selectByExample(weekend);
Because it is expected to be able to query the information of multiple students , So you should use selectByExample, And use List To receive the return message ;
2. andIn
Use andIn sentence , It is equivalent to using where Field name in A value range Of SQL sentence
If we want to number in the student class 12345678 On the basis of , The student number is found to be 0001、0002 and 0003 Classmate , Then you can write like this :
Weekend<StudentInfo> weekend = Weekend.of(StudentInfo.class);
WeekendCriteria<StudentInfo, Object> weekendCriteria = weekend.weekendCriteria();
weekendCriteria.andEqualTo(StudentInfo::getClassId, "12345678");
List<String> studentIdList = Arrays.asList("0001", "0002", "0003");
weekendCriteria.andIn(StudentInfo::getStudentId, studentIdList);
weekendCriteria.andEqualTo(StudentInfo::getdeletedStatus, 0);
List<StudentInfo> infoList = studentInfoMapper.selectByExample(weekend);
3. andNotEqualTo
It happens to be with andEqualTo contrary ;
4. andNotIn
It happens to be with andIn contrary ;
5. andGreaterThanOrEqualTo
seeing the name of a thing one thinks of its function , This is greater than or equal to , It can also be used to filter the data according to the modification date , It is written as follows :
weekendCriteria.andGreaterThanOrEqualTo(StudentInfo::getMtime, DateUtils.transferString2Date(LocalDate.now().toString()));
among ,DateUtils.transferString2Date Methods can refer to another article of mine : take String To date, Convenient and quick ;
6. andLike
have access to andLike Fuzzy query , But be careful , Fuzzy query will scan the whole table , Slow speed , It is easy to cause slow queries ( About slow queries , You can refer to another article of mine : What is slow query ? How to optimize ?);
If we want to find all names with red The information of my classmates , It can be written like this :
Weekend<StudentInfo> weekend = Weekend.of(StudentInfo.class);
WeekendCriteria<StudentInfo, Object> weekendCriteria = weekend.weekendCriteria();
weekendCriteria.andLike(StudentInfo::getName, "%" + " red " + "%");
weekendCriteria.andEqualTo(StudentInfo::getdeletedStatus, 0);
List<StudentInfo> infoList = studentInfoMapper.selectByExample(weekend);
If there are a lot of fuzzy searches in the database 、 Text matching , Consider making ElasticSearch,ElasticSearch It's a Distributed 、 High performance 、 High availability 、 Telescopic 、RESTful style Search and data analysis engine .
7. summary
When there are many query conditions , We can flexibly put all conditions together ,tkMapper Let's avoid handwriting to the greatest extent SQL sentence , Greatly improved our development efficiency .
边栏推荐
- 使用base64对图片进行编码、对byte[]进行编码
- JS copy text to clipboard
- 网络通信安全部分笔记——OSPF理论及实验
- Notes 2 of network communication security
- tkMapper之使用Weekend拼接条件进行条件查询
- Hand to hand teaching - using native POI to import and export excel and the basic operations of Alibaba's easyexcel
- ES6--Set
- Summer precipitation Web Learning -- PHP Foundation
- antd setFieldsValue警告问题 Cannot use `setFieldsValue` until you use `getFieldDecorator` or
- FTP upload file script description
猜你喜欢

ES6 -- class

Convert list data to tree data

操作系统笔记——Windows应急响应和安全加固

Dense Digital Economy: using passwords to "search for pearls in the deep sea"

内网渗透笔记——注册表自启动与msi提权

MSF infiltrates Win2003 with eternal blue

Infrastructure nftscan officially released Solana network NFT browser

摩斯隐私计算一体机全项通过深圳国金测评中心83项测评

How did the situation that NFT trading market mainly uses eth standard for trading come into being?

37.js -- member operation of object and operation of prototype object (mainly related program examples)
随机推荐
Intranet penetration notes - Three Layer Discovery and four layer discovery
MySQL-多表查询-内连接/外连接/自连接
Experimental report on using spark to predict repeat customers
Php+jmeter simulates high concurrency scenarios. Code attached.
36.js-- prototype chain 2-- (mainly written test questions)
MSF infiltrates Win2003 with eternal blue
WKWebView之离线加载以及遇到的问题
摩斯隐私计算一体机全项通过深圳国金测评中心83项测评
Some small problems encountered in using Baidu lightweight server LS
什么是慢查询?如何优化?
About the installation and use of visual studio 2022
WP of the southwest division of the 15th National College Students Information Security Competition (ciscn) 2022
ES6 -- let and Const
MSF利用永恒之蓝渗透win2003
Wechat payment refund PHP
JS time object
40.js -- the same name identifier promotion problem
Compilation principle - parser design
Es6--string (string)
内网渗透笔记——二层发现