栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

3.12mybatisplus学习

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

3.12mybatisplus学习

1.自动填充

2.乐观锁

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

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

3.使用mp进行简单查询

//1使用mp分页插件进行分页查询
@Test
public void testSelect3() throws Exception{
    Page page = new Page<>(1,3);
    Page userPage = userMapper.selectPage(page, null);
    //返回对象得到分页所有数据
    long pages = userPage.getPages(); //总页数
    long current = userPage.getCurrent(); //当前页
    List 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 users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
    System.out.println(users);

}
//3使用map进行简单的多个条件查询
@Test
public void testSelectt2() throws Exception{
   Map columnMap = new HashMap<>();
   columnMap.put("name", "jack");
   columnMap.put("age", 20);
    List 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 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/763860.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号