M87星云

导航

Mybatis plus 常用删除方式

    @Autowired
    private Test3Dao test3Dao;

    /**
     * 指定id删除
     */
    @Test
    public void testDeleteId(){
        int result = test3Dao.deleteById(3);
        log.info("删除结果:{}",result);
    }

    /**
     * 指定集合id删除
     */
    @Test
    public void deleteBatchIds(){
        int result = test3Dao.deleteBatchIds(Arrays.asList(1,2));
        log.info("删除结果:{}",result);
    }

    /**
     * 根据的字段=值进行删除,可以写多个字段和值, 条件是and关系
     * 比如:
     * DELETE FROM Test3 WHERE name = ? AND id = ?
     */
    @Test
    public void deleteByMap(){
        Map<String,Object> map = new HashMap<>();
        map.put("name","boat1");
        map.put("id",5);
        int result = test3Dao.deleteByMap(map);
        log.info("删除结果:{}",result);
    }

 

posted on 2021-09-28 21:30  挽留匆匆的美丽  阅读(970)  评论(0编辑  收藏  举报