Mybatis_plus基本查询,删除

通过id查询

//测试查询
    @Test
    public void testSelectById(){
        //查询单个id
        User user=userMapper.selectById(1);
        System.out.println(user);
        //查询多个id
        List<User> users=userMapper.selectBatchIds(Arrays.asList(1,2,3,4));
        users.forEach(System.out::println);
    }

条件查询(通过map)

 //条件查询
    @Test
    public void testSelectByMap(){
        HashMap<String,Object> hash=new HashMap<String,Object>();
        //自定义查询
        hash.put("name","gem");
        hash.put("age",18);
        userMapper.selectByMap(hash);
    }

分页查询

//分页查询,在网页使用极多
    @Test
    public void testPage(){
        //当前页:1   页面大小:2
        Page<User> page=new Page<>(1,2);
        userMapper.selectPage(page,null);
        page.getRecords().forEach(System.out::println);
        System.out.println(page.getTotal());
    }

 

通过id删除

//删除测试
    @Test
    public void testDeleteById(){
        userMapper.deleteById(1804914009888006148L);
    }
    //通过id批量删除
    @Test
    public void testDeleteBatchIds(){
        userMapper.deleteBatchIds(Arrays.asList(1804892484724183042L,1804914009888006146L));
    }

条件删除(通过map)

//通过map删除
    @Test
    public void testDeleteByMap(){
        HashMap<String,Object> hash=new HashMap<String,Object>();
        hash.put("name","田先生天下第一帅");
        userMapper.deleteByMap(hash);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值