-
13333333333333333
查看全部 -
selectByMap()
查看全部 -
selectBatchIds(@Param(Constants.COLLECTION)Collection<? extends Serializable> idList);
根據(jù)id集合獲取對象集合list
Arrays.asList(id1,id2)將list集合參數(shù)進行forEach輸出:
userList.forEach(System.out::println);查看全部 -
selectById(...id) 根據(jù)主鍵獲取實體
查看全部 -
@TableField(exist=false)? //exist=false表示數(shù)據(jù)庫字段并無該屬性
private String remark;查看全部 -
@Transient 注解的實體類字段不參數(shù)序列化過程
查看全部 -
其它字段指定數(shù)據(jù)庫中對應(yīng)名稱
@TableField("name")//數(shù)據(jù)庫中叫name
private String realName;查看全部 -
@TableId 注解到實體類的表id字段 可以取代表中id主鍵不叫id的別名的
對應(yīng)駝峰寫法 如 實體類 memberId, 表中 member_id查看全部 -
@TableName 在實體類執(zhí)行表名 別名
查看全部 -
zzzccc查看全部
-
asdasdagasdfgadf查看全部
-
asdasda
查看全部 -
package?com.mp; import?com.baomidou.mybatisplus.core.conditions.Wrapper; import?com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import?com.baomidou.mybatisplus.core.toolkit.Wrappers; import?com.mp.dao.UserMapper; import?com.mp.entity.User; import?org.junit.Test; import?org.junit.runner.RunWith; import?org.springframework.beans.factory.annotation.Autowired; import?org.springframework.boot.test.context.SpringBootTest; import?org.springframework.test.context.junit4.SpringRunner; import?java.util.Arrays; import?java.util.HashMap; import?java.util.List; import?java.util.Map; /** ?*?@Description ?*?@auther?mohuani ?*?@create?2019-12-25?11:37 ?*/ @RunWith(SpringRunner.class) @SpringBootTest public?class?RetrieveTest?{ ????@Autowired ????private?UserMapper?userMapper; ????@Test ????public?void?selectById()?{ ????????User?user?=?userMapper.selectById(1088250446457389058L); ????????System.out.println(user); ????} ????@Test ????public?void?selectBatchIds()?{ ????????List<Long>?list?=?Arrays.asList(1088248166370832385L,?1094590409767661570L,?1209509417456001025L); ????????List<User>?userList?=?userMapper.selectBatchIds(list); ????????userList.forEach(System.out::println); ????} ????@Test ????public?void?selectByMap()?{ ????????Map<String,?Object>?columnMap?=?new?HashMap<>(); ????????columnMap.put("name",?"李藝偉"); ????????columnMap.put("age",?28); ????????List<User>?userList?=?userMapper.selectByMap(columnMap); ????????userList.forEach(System.out::println); ????} ????/** ?????*?1、名字中包含雨并且年齡小于40 ?????*?????name?like?'%雨%'?and?age<40 ?????*/ ????@Test ????public?void?selectByWrapper()?{ ????????QueryWrapper<User>?queryWrapper?=?new?QueryWrapper<>(); ????????queryWrapper.like("name",?"雨").lt("age",?40); ????????List<User>?userList?=?userMapper.selectList(queryWrapper); ????????userList.forEach(System.out::println); ????} ????/** ?????*?2、名字中包含雨年并且齡大于等于20且小于等于40并且email不為空 ?????*????name?like?'%雨%'?and?age?between?20?and?40?and?email?is?not?null ?????*/ ????@Test ????public?void?selectByWrapper2()?{ ????????QueryWrapper<User>?queryWrapper?=?new?QueryWrapper<>(); ????????queryWrapper.like("name",?"雨").between("age"?,20?,40).isNotNull("email"); ????????List<User>?userList?=?userMapper.selectList(queryWrapper); ????????userList.forEach(System.out::println); ????} ????/** ?????*?3、名字為王姓或者年齡大于等于25,按照年齡降序排列,年齡相同按照id升序排列 ?????*????name?like?'王%'?or?age>=25?order?by?age?desc,id?asc ?????*/ ????@Test ????public?void?selectByWrapper3()?{ ????????QueryWrapper<User>?queryWrapper?=?new?QueryWrapper<>(); ????????queryWrapper.likeRight("name",?"王").or().gt("age",?25).orderByDesc("age").orderByAsc("id"); ????????List<User>?userList?=?userMapper.selectList(queryWrapper); ????????userList.forEach(System.out::println); ????} }
查看全部 -
一、查詢需求
1、名字中包含雨并且年齡小于40
?????? name like '%雨%' and age<40
2、名字中包含雨年并且齡大于等于20且小于等于40并且email不為空
?? name like '%雨%' and age between 20 and 40 and email is not null
3、名字為王姓或者年齡大于等于25,按照年齡降序排列,年齡相同按照id升序排列
?? name like '王%' or age>=25 order by age desc,id asc
4、創(chuàng)建日期為2019年2月14日并且直屬上級為名字為王姓
????? date_format(create_time,'%Y-%m-%d')='2019-02-14' and manager_id in (select id from user where name like '王%')
5、名字為王姓并且(年齡小于40或郵箱不為空)
??? name like '王%' and (age<40 or email is not null)
6、名字為王姓或者(年齡小于40并且年齡大于20并且郵箱不為空)
??? name like '王%' or (age<40 and age>20 and email is not null)
7、(年齡小于40或郵箱不為空)并且名字為王姓
??? (age<40 or email is not null) and name like '王%'
8、年齡為30、31、34、35
??? age in (30、31、34、35)?
9、只返回滿足條件的其中一條語句即可
limit 1
二、select中字段不全部出現(xiàn)的查詢
10、名字中包含雨并且年齡小于40(需求1加強版)
第一種情況:select id,name
?????? ?????????? from user
?????? ?????????? where name like '%雨%' and age<40
第二種情況:select id,name,age,email
?????? ?????????? from user
?????? ?????????? where name like '%雨%' and age<40
三、統(tǒng)計查詢:
11、按照直屬上級分組,查詢每組的平均年齡、最大年齡、最小年齡。
并且只取年齡總和小于500的組。
select avg(age) avg_age,min(age) min_age,max(age) max_age
from user
group by manager_id
having sum(age) <500
查看全部 -
一、查詢需求
1、名字中包含雨并且年齡小于40
?????? name like '%雨%' and age<40
2、名字中包含雨年并且齡大于等于20且小于等于40并且email不為空
?? name like '%雨%' and age between 20 and 40 and email is not null
3、名字為王姓或者年齡大于等于25,按照年齡降序排列,年齡相同按照id升序排列
?? name like '王%' or age>=25 order by age desc,id asc
4、創(chuàng)建日期為2019年2月14日并且直屬上級為名字為王姓
????? date_format(create_time,'%Y-%m-%d')='2019-02-14' and manager_id in (select id from user where name like '王%')
5、名字為王姓并且(年齡小于40或郵箱不為空)
??? name like '王%' and (age<40 or email is not null)
6、名字為王姓或者(年齡小于40并且年齡大于20并且郵箱不為空)
??? name like '王%' or (age<40 and age>20 and email is not null)
7、(年齡小于40或郵箱不為空)并且名字為王姓
??? (age<40 or email is not null) and name like '王%'
8、年齡為30、31、34、35
??? age in (30、31、34、35)?
9、只返回滿足條件的其中一條語句即可
limit 1
二、select中字段不全部出現(xiàn)的查詢
10、名字中包含雨并且年齡小于40(需求1加強版)
第一種情況:select id,name
?????? ?????????? from user
?????? ?????????? where name like '%雨%' and age<40
第二種情況:select id,name,age,email
?????? ?????????? from user
?????? ?????????? where name like '%雨%' and age<40
三、統(tǒng)計查詢:
11、按照直屬上級分組,查詢每組的平均年齡、最大年齡、最小年齡。
并且只取年齡總和小于500的組。
select avg(age) avg_age,min(age) min_age,max(age) max_age
from user
group by manager_id
having sum(age) <500
查看全部
舉報