3.12mybatisplus学习

1.自动填充

2.乐观锁

当要更新一条记录的时候,希望这条记录没有被别人更新,也就是说实现线程安全的数据更新 

当需要修改时,自动的实现version加1

3.使用mp进行简单查询

//1使用mp分页插件进行分页查询
@Test
public void testSelect3() throws Exception{
    Page<User> page = new Page<>(1,3);
    Page<User> userPage = userMapper.selectPage(page, null);
    //返回对象得到分页所有数据
    long pages = userPage.getPages(); //总页数
    long current = userPage.getCurrent(); //当前页
    List<User> records = userPage.getRecords(); //查询数据集合
    long total = userPage.getTotal(); //总记录数
    boolean hasNext = userPage.hasNext();  //下一页
    boolean hasPrevious = userPage.hasPrevious(); //上一页

    System.out.println(pages);
    System.out.println(current);
    System.out.println(records);
    System.out.println(total);
    System.out.println(hasNext);


}

//2简单的根据id查询
@Test
public void testSelect1() throws Exception{
    List<User> users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
    System.out.println(users);

}
//3使用map进行简单的多个条件查询
@Test
public void testSelectt2() throws Exception{
   Map<String, Object> columnMap = new HashMap<>();
   columnMap.put("name", "jack");
   columnMap.put("age", 20);
    List<User> users = userMapper.selectByMap(columnMap);
    System.out.println(users);

}

4.删除操作

删除与实现逻辑删除

//1  id删除
@Test
public void testDeleteId() throws Exception{
    int i = userMapper.deleteById(5);
    System.out.println(i);
}
//2  批量删除
@Test
public void testDeleteBatchIds(){
    int deleteBatchIds = userMapper.deleteBatchIds(Arrays.asList( 2, 3));
    System.out.println(deleteBatchIds);

}
//3  简单条件删除
@Test
public void testDeleteByMap() throws Exception{
    HashMap<String,Object> map = new HashMap();
    map.put("name", "Sandy");
    map.put("age",21);
    int i = userMapper.deleteByMap(map);
    System.out.println(i);

}

逻辑删除

可以通过mp的自动填充对deleted进行初始化 

5.条件构造器查询

wrapper

查询方式

查询方式

说明

setSqlSelect

设置 SELECT 查询字段

where

WHERE 语句,拼接 + WHERE 条件

and

AND 语句,拼接 + AND 字段=值

andNew

AND 语句,拼接 + AND (字段=值)

or

OR 语句,拼接 + OR 字段=值

orNew

OR 语句,拼接 + OR (字段=值)

eq

等于=

allEq

基于 map 内容等于=

ne

不等于<>

gt

大于>

ge

大于等于>=

lt

小于<

le

小于等于<=

like

模糊查询 LIKE

notLike

模糊查询 NOT LIKE

in

IN 查询

notIn

NOT IN 查询

isNull

NULL 值查询

isNotNull

IS NOT NULL

groupBy

分组 GROUP BY

having

HAVING 关键词

orderBy

排序 ORDER BY

orderAsc

ASC 排序 ORDER BY

orderDesc

DESC 排序 ORDER BY

exists

EXISTS 条件语句

notExists

NOT EXISTS 条件语句

between

BETWEEN 条件语句

notBetween

NOT BETWEEN 条件语句

addFilter

自由拼接 SQL

last

拼接在最后,例如:last(“LIMIT 1”)

6.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值