mybatisPlus

配置文件

常用注解

  1. @TableId
    - value:指定表中主键列的列名,可省略
    - type:指定主键策略
  2. @TableName 在实体类上指定表名
  3. @TableFieId
    - value:指定表中的列名
    - exists:false (默认值为true,false代表不是数据库的字段

新增

  1. insert(Pojo):根据实体类每个属性进行非空判断,非空 的属性对应的字段都会出现在Sql语句中

    • 获取返回的主键值 pojo.getId();
  2. inesrtAllColumn(Pojo); 不管属性是否为空,属性对应的字段都会出现在Sql语句中

更新

  1. updateById(Pojo) 为空的字段不会出现在SQL语句中,where条件是主键Id
  2. updateAllColumnById(Pojo) 所以字段都会出现在Sql语句中分

查询

  1. selectById(Seriberized id); Object类型的Id

  2. selectOne(Pojo); 通过name + id进行查询

  3. selectBachIds(arrayList); where In

        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        List<Employee> employeeList = employeeMapper.selectBatchIds(arrayList);
    
  4. selectByMap 根据查询条件返回List集合

     Map<String,Object> maps=new HashMap<>();
     maps.put("last_name", "tom3");
     List<Employee> employeeList = employeeMapper.selectByMap(maps);
     System.out.println(employeeList);
    
  5. selectPage(); 内存分页

     List<Employee> employeeList = employeeMapper.selectPage(new Page<>(1, 2), null);
    

删除

  1. deleteById(int id); 根据id删除 返回影响的行数

  2. deleteByMap(Map maps);

      //根据条件批量删除 where ... and ...
      Map<String,Object> maps=new HashMap<>();
      maps.put("last_name","tom3");
      Integer integer = employeeMapper.deleteByMap(maps);
      System.out.println(integer);
    
  3. deleteBatchIds(list);

       ArrayList<Integer> arrayList = new ArrayList<>();
       arrayList.add(4);
       arrayList.add(5);
       Integer integer = employeeMapper.deleteBatchIds(arrayList);
       System.out.println(integer);
    
mybatisPlusmybatisPlus spicyChicken___ 发布了12 篇原创文章 · 获赞 0 · 访问量 285 私信 关注
上一篇:POJO(Plain Old Java Object)和DTO(Data Transfer Object)有什么区别?


下一篇:POJO,JavaBean,entity的理解