Fun 3 minutes per day MyBatis-Plus - Configuration Environment
Fun day three minutes MyBatis-Plus - 2. General Queries
Fun 3 minutes MyBatis-Plus daily - 3. Advanced Search
Download: https: //github.com/Jackson0714/study-mybatis-plus.git
mybatis-plus search function is very powerful, the one we introduced the common queries mybatis-plus, which we introduced an advanced query features of mybatis-plus. Explained through several query requirements.
Prepare data
User
Table structure is as follows:
id | name | age | |
---|---|---|---|
1 | Our | 18 | [email protected] |
2 | Jack | 20 | [email protected] |
3 | Tom | 28 | [email protected] |
4 | Sandy | 21 | [email protected] |
5 | Billie | 24 | [email protected] |
First, the case summary (the first wave)
1.1 query name contains "Ja" and users younger than 30
Difficulty coefficient ★ ☆
1.2 query contains the name "a" and older than 15 and is equal to the age of 25 or less, and the email is not empty
Difficulty coefficient ★ ☆
1.3 at the beginning of the query the name "J" is equal to and greater than the age of 25, in descending order according to age, the same age, according to the ascending order id
Difficulty factor ★★★
Second, explain the case
1.1 query name contains "Ja" and users younger than 30
Difficulty coefficient ★ ☆
Visits like, lt usage
name LIKE '%Ja%' age < 30
1 / * 2 * Description: Example 2.1 query name contains "Ja" and users younger than 30 3 * Author: blog Garden - Wukong chat Architecture 4 * Time: 2019-01-20 5 * Github: HTTPS: // GitHub .com / Jackson0714 / Study-MyBatis-plus.git . 6 * blog Park: https://www.cnblogs.com/jackson0714 . 7 * * / . 8 @Test . 9 public void testSelectByQueryWrapper () { 10 System.out.println (( "----- query contains the name" of Ja "and a user younger than 30 ------" )); . 11 QueryWrapper <the user> = queryWrapper new new QueryWrapper <> (); 12 is queryWrapper.like("name", "ja").lt("age", 30); 13 List<User> userList = userMapper.selectList(queryWrapper); 14 userList.forEach(System.out::println); 15 }
1.2 query contains the name "a" and older than 15 and is equal to the age of 25 or less, and the email is not empty
★ ☆ degree of difficulty of
visits between usage
SQL语句:name LIKE '%a%' AND age BETWEEN 15 AND 25 AND email IS NOT NULL
1 / * 2 * Description: Example 1.2 query contains the name "a" and older than 15 and is equal to the age of 35 or less, and the email is not empty 3 * OF: blog Park - Monkey talk architecture 4 * Time: 2019-01- 20 5 * Github: https://github.com/Jackson0714/study-mybatis-plus.git 6 * Park blog: https://www.cnblogs.com/jackson0714 7 * * / 8 @Test 9 public void testSelectByQueryWrapper2 ( ) { 10 System.out.println (( "----- query contains the name" a "and older than 15 and is equal to the age of 25 or less, and the email is not empty ------" )); 11 QueryWrapper <the User> = queryWrapper new new QueryWrapper <> (); 12 //queryWrapper.like("name", "a").ge("age", 15).le("age", 25).isNotNull("email"); 13 queryWrapper.like("name", "a").between("age", 15,25).isNotNull("email"); 14 List<User> userList = userMapper.selectList(queryWrapper); 15 userList.forEach(System.out::println); 16 }
1.3 at the beginning of the query the name "J" is equal to and greater than the age of 25, in descending order according to age, the same age, according to the ascending order id
Difficulty factor ★★★
Study likeRight, orderByDesc, orderByAsc usage
SQL语句:name LIKE 'J%' or age > 25 ORDER BY age desc, id ASC
1 / * 2 * Description: Example 1.3 query the name "J" at the beginning and older than 26, in descending order according to age, the age of the same arranged in id ascending . 3 * the SQL statement: name LIKE 'J%' or age> 26 ORDER BY age desc, the above mentioned id ASC 4 * author: blog garden - Wukong talk architecture 5 * time: 2019-01-20 6 * Github: https://github.com/Jackson0714/study-mybatis-plus.git 7 * Park blog: HTTPS : //www.cnblogs.com/jackson0714 . 8 * * / . 9 @Test 10 public void testSelectByQueryWrapper3 () { . 11 System.out.println (( "----- query contains the name" a "and older than 26, in descending order according to age, the same age, arranged in ascending order ------ id " )); 12 QueryWrapper<User> queryWrapper = new QueryWrapper<>(); 13 queryWrapper.likeRight("name","J").or().gt("age",26).orderByDesc("age") 14 .orderByAsc("id"); 15 List<User> userList = userMapper.selectList(queryWrapper); 16 userList.forEach(System.out::println); 17 }
Fun 3 minutes per day MyBatis-Plus - Configuration Environment
Fun day three minutes MyBatis-Plus - 2. General Queries
Fun 3 minutes MyBatis-Plus daily - 3. Advanced Search
No public concern: Wukong talk architecture, reply pmp, pmp receive information! Reply Wukong, to receive information architect!
Author: Wukong talk architecture
Source: http://www.cnblogs.com/jackson0714/
About the author: focus on mobile development. If you have questions or suggestions, please enlighten me a lot!
Disclaimer: This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original article page link in the apparent position.
Hereby declare: All comments and private messages will reply in the first time. We greatly welcome the garden also correct errors and common progress. Or direct private letter I
in solidarity Bloggers: If you think the article is helpful to you, you can click on the bottom right corner of the article [Recommended] it. You are encouraged to adhere to the original author continued writing and maximum power!
Wukong chat Architecture
I am concerned with you a little bit of progress every day!
There are 111 books presented ~~