@Autowired 
    ISongsService  songsService; 
@Test 
    public  void  add ( ) { 
        Songs  s= new  Songs ( null , "11" , "xx" , null , "xx歌曲" , "2020-02-12" ) ; 
        songsService. save ( s) ; 
        System . out. println ( s) ; 
    } 
 
boolean  updateById ( T  entity) ; 
@Autowired 
    ISongsService  songsService; 
@Test 
    public  void  updateOne ( ) { 
        
        Songs  songs =  new  Songs ( 1002 ,  "凤凰传奇" ,  null ,  null ,  "策马奔腾" ,  null ) ; 
        boolean  b =  songsService. updateById ( songs) ; 
        System . out. println ( "更新结果:" + b) ; 
    } 
 
 
 
 
boolean  updateBatchById ( Collection < T > ) ; 
@Test 
    public  void  updateMore ( ) { 
        
        List < Songs > = new  ArrayList < > ( ) ; 
        list. add ( new  Songs ( 1002 ,  "周杰伦" ,  null ,  null ,  "七里香" ,  null ) ) ; 
        list. add ( new  Songs ( 1004 ,  "汪苏泷" ,  null ,  null ,  "三国杀" ,  null ) ) ; 
        list. add ( new  Songs ( 1005 ,  "凤凰传奇" ,  null ,  null ,  "荷塘月色" ,  null ) ) ; 
        boolean  b =  songsService. updateBatchById ( list) ; 
        System . out. println ( "批量更新结果:" + b) ; 
    } 
 
 
 
 
boolean  removeById ( Serializable  id) ; 
    @Test 
    public  void  deleteOne ( ) { 
        boolean  b =  songsService. removeById ( 1004 ) ; 
        System . out. println ( "删除单条结果:" + b) ; 
    } 
 
 
 
 
boolean  removeBatchByIds ( Collection < ? > ) 
 
    @Test 
    public  void  deleteMore ( ) { 
        List < Integer > = new  ArrayList < > ( ) ; 
        list. add ( 1002 ) ; 
        list. add ( 1005 ) ; 
        boolean  b =  songsService. removeBatchByIds ( list) ; 
        System . out. println ( "结果:" + b) ; 
    } 
 
 
 
 
并不是真正的从数据表删除这条数据,而是将表中的逻辑删除字段的值变更为1(此时就代表逻辑删除成功了)
注意:①若是自定义sql,就需要自己写where子句
     ②默认是以0表示未删除,1表示已删除
     ③逻辑删除本质就是更改表的某个字段,在查询和更新的时候给定规则去进行筛选
 
 
 @TableLogic 
    private  Integer  del; 
package  com. zlz. entity ; 
import  com. baomidou. mybatisplus. annotation.  IdType ; 
import  com. baomidou. mybatisplus. annotation.  TableId ; 
import  java. io.  Serializable ; 
import  java. util.  Date ; 
import  com. baomidou. mybatisplus. annotation.  TableLogic ; 
import  com. baomidou. mybatisplus. annotation.  Version ; 
import  lombok.  * ; 
@AllArgsConstructor 
@NoArgsConstructor 
@Data 
public  class  Songs  implements  Serializable  { 
    private  static  final  long  serialVersionUID =  1L ; 
    @TableId ( value =  "id" ,  type =  IdType . AUTO ) 
    private  Integer  id; 
    private  String  singerName; 
    private  String  album; 
    private  String  albumImg; 
    private  String  name; 
    
    private  String  releaseDate; 
    
    @TableLogic 
    private  Integer  del; 
} 
@Test 
    public  void  remove ( ) { 
        boolean  b =  songsService. removeById ( 1006 ) ; 
        System . out. println ( "逻辑删除结果: " + b) ; 
    } 
 
 
 
 
@Test 
public  void  find ( ) { 
    Songs  s= songsService. getById ( 1006 ) ; 
    System . out. println ( "逻辑删除后再查该数据的结果:" + s) ; 
} 
 
 
@Test 
    public  void  updateOne ( ) { 
        
        Songs  songs =  new  Songs ( 1006 ,  "凤凰传奇" ,  null ,  null ,  "策马奔腾" ,  null , null ) ; 
        boolean  b =  songsService. updateById ( songs) ; 
        System . out. println ( "配置了逻辑删除后,更新的结果为:" + b) ; 
    } 
 
 
 
 
① 当要更新一条记录的时候,希望这条记录没有被别人更新
② 为了解决多个用户同时修改相同的数据时的冲突问题
③ 乐观锁是业务的实现(代码不加锁)
④ 修改时,会根据版本修改,修改成功后会递增版本
⑤ 乐观锁只是修改的时候起作用,支持的数据类型只有:int,Integer,long,Long,Date,Timestamp,LocalDateTime
 
 
@Version 
    private  Integer  v; 
package  com. zlz. entity ; 
import  com. baomidou. mybatisplus. annotation.  IdType ; 
import  com. baomidou. mybatisplus. annotation.  TableId ; 
import  java. io.  Serializable ; 
import  java. util.  Date ; 
import  com. baomidou. mybatisplus. annotation.  TableLogic ; 
import  com. baomidou. mybatisplus. annotation.  Version ; 
import  lombok.  * ; 
@AllArgsConstructor 
@NoArgsConstructor 
@Data 
public  class  Songs  implements  Serializable  { 
    private  static  final  long  serialVersionUID =  1L ; 
    @TableId ( value =  "id" ,  type =  IdType . AUTO ) 
    private  Integer  id; 
    private  String  singerName; 
    private  String  album; 
    private  String  albumImg; 
    private  String  name; 
    private  String  releaseDate; 
    
    @Version 
    private  Integer  v; 
} 
interceptor. addInnerInterceptor ( new  OptimisticLockerInnerInterceptor ( ) ) ; 
package  com. zlz. config ; 
import  com. baomidou. mybatisplus. annotation.  DbType ; 
import  com. baomidou. mybatisplus. extension. plugins.  MybatisPlusInterceptor ; 
import  com. baomidou. mybatisplus. extension. plugins. inner.  OptimisticLockerInnerInterceptor ; 
import  com. baomidou. mybatisplus. extension. plugins. inner.  PaginationInnerInterceptor ; 
import  org. mybatis. spring. annotation.  MapperScan ; 
import  org. springframework. context. annotation.  Bean ; 
import  org. springframework. context. annotation.  Configuration ; 
@Configuration 
@MapperScan ( "com.zlz.mapper" ) 
public  class  PlusConfig  { 
    @Bean 
    public  MybatisPlusInterceptor  mybatisPlusInterceptor ( )  { 
        MybatisPlusInterceptor  interceptor =  new  MybatisPlusInterceptor ( ) ; 
        
        PaginationInnerInterceptor  pi =  new  PaginationInnerInterceptor ( ) ; 
        pi. setDbType ( DbType . MYSQL ) ; 
        pi. setOverflow ( true ) ; 
        interceptor. addInnerInterceptor ( pi) ; 
        
        interceptor. addInnerInterceptor ( new  OptimisticLockerInnerInterceptor ( ) ) ; 
        return  interceptor; 
    } 
} 
@Test 
public  void  positiveLock ( ) { 
    
    Songs  s1 =  songsService. getById ( 1006 ) ; 
    Songs  s2 =  songsService. getById ( 1006 ) ; 
    
    s1. setName ( "光年之外" ) ; 
    
    boolean  b1 =  songsService. updateById ( s1) ; 
    System . out. println ( "第一个用户修改的结果: " + b1) ; 
    
    boolean  b2 =  songsService. updateById ( s2) ; 
    System . out. println ( "第二个用户修改的结果: " + b2) ; 
} 
 
 
 
 
@RequestMapping ( "update" ) 
@ResponseBody 
public  boolean  update ( ) { 
    Songs  s =  songsService. getById ( 2 ) ; 
    return  songsService. updateById ( s) ; 
}