First, add, delete, change and check

select

  • Queries based on attribute values in entities

    List<T> selct (T record) ;
    Copy the code
  • To query by primary key field, the parameter must contain the full primary key attribute

    T selectByPrimaryKey(Object key);
    Copy the code
  • Query all results

    List<T> selectAll( );
    Copy the code
  • Queries based on attributes in entities can have only one return value, and multiple results throw exceptions

    T selectOne(T record);
    Copy the code
  • Query totals based on attributes in entities

    int selectCount(T record);
    Copy the code

insert

  • When an entity is saved, the null attribute is also saved. The database default is not used

    int insert(T record);
    Copy the code
  • To save an entity, the null attribute is not saved, and the database default value is used

    int insertSelective(T record);
    Copy the code

update

  • Update all fields of the entity based on the primary key, null values will be updated

    int updateByPrimaryKey(T record);
    Copy the code
  • Update values whose attributes are not NULL based on the primary key

    int updateByPrimaryKeySelective(T record);
    Copy the code

delete

  • Delete based on entity attributes as conditions

    int delete(T record);
    Copy the code
  • To delete by primary key field, the method parameter must contain the full primary key attribute

    int deleteByPrimaryKey(Object key);
    Copy the code

Example

Preparation before use

// Create an object, passing in the.class of the class being operated on
Example example = new Example(Goods.class);
Example.Criteria criteria = example.createCriteria();
Copy the code

Set conditions

  • Field name Is the attribute name of the entity class, not the database field name

    The serial number methods role
    1 Example.orderby (field name).asc(); Add ascending order conditions
    2 Example.orderby (field name).desc(); Add descending sort criteria
    3 example. setDistinct(false); Delete duplicates, Boolean,true for records that do not duplicate
    4 Criteria. AndIsNull (field name); Add the condition that field xx is null
    5 Criteria. AndIsNotNull (field name); Add the condition that field xx is not null
    6 Criteria. AndEqualTo (criteria,value); Add xx field equals value condition
    7 Criteria. AndNotEqualTo (field name,value); Adding xx fields does not equal a value condition
    8 Criteria. AndGreaterThan (column name,value); Add xx field greater than value condition
    9 Criteria. AndGreaterThanOrEqualTo (field name, value); Add xx field greater than or equal to vAUe condition
    11 Criteria. AndLessThan (criteria name,value); Add xx field less than value condition
    12 Criteria. AndLessThanOrEqualTo (field name, value); Add a condition that the xx field is less than or equal to value
    13 Criteria. AndIn (field name,list); Add xx field values to the List condition
    14 Criteria. AndNotIn (criteria,list); Add xx field value not in List condition
    15 Criteria. AndLike (field name, ‘%’ +value+ ‘%’); Add the fuzzy query condition whose field xx is vaue
    16 Criteria. AndNotLike (field name, ‘%’ +value+ ‘%’); Add a fuzzy query condition in which the xx field value is not value
    17 Criteria. AndBetween (field name,value1,value2); Add xx field value condition between value1 and value2
    18 Criteria. AndNotBetween (field name,value1,value2); Add the condition that the value of xx field is not between value1 and value2

select

  • Query according to the Example condition

    List<T> selectByExample(Object example);
    Copy the code
  • Query the total number based on the Example condition

    int selectCountByExample(Object example);
    Copy the code
  • Query the specified field method

    Example example = new Example(User.class);
         example.selectProperties("headImg"."username"."introduction")
           .and()
          .andEqualTo("userId",userId);
    User user = userMapper.selectOneByExample(example);
    Copy the code

update

  • Update all attributes contained in the entity Record according to the Example condition, and null values are updated

    int updateByExample(@Param("record") T record, @Param("example") Object example);
    Copy the code
  • Update the entity Record containing property values that are not null based on the Example condition

    int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);
    Copy the code

delete

  • Delete data according to the Example condition

    int deleteByExample(Object example);
    Copy the code