例: notBetween(age, 18, 30) —-> age not between 18 and 30
like
LIKE %值%
例: like(name, 王) —-> name like %王%
notlike
NOT LIKE %值%
例: notLike(name, 王) —-> name not like %王%
likeLeft
LIKE %值
例: likeLeft(name, 王) —-> name like %王
likeRight
LIKE 值%
例: likeRight(name, 王) —-> name like 王%
notLikeLeft
NOT LIKE %值
例: notLikeLeft(name, 王) —-> name not like %王
notLikeRight
NOT LIKE 值% 例: notLikeRight(name, 王) —-> name not like 王%
isNull
字段 IS NULL
例: isNull(name) —-> name is null
isNotNull
字段 IS NOT NULL
例: isNotNull(name) —-> name is not null
in
字段 IN (value.get(0), value.get(1), …)
例: in(age, {1, 2, 3}) —-> age in (1, 2, 3)
字段 IN (v0, v1, …)
例: in(age, 1, 2, 3) —-> age in (1, 2, 3)
notIn
字段 NOT IN (value.get(0), value.get(1), …)
例: notIn(age, {1, 2, 3}) —-> age not in (1, 2, 3)
字段 NOT IN (v0, v1, …)
例: notIn(age, 1, 2, 3) —-> age not in (1, 2, 3)
inSql
字段 IN ( sql语句 )
例: inSql(age, 1, 2, 3, 4, 5, 6) —-> age in (1, 2, 3, 4, 5, 6)
例: inSql(id, select id from table where id < 3) —-> id in (select id from table where id < 3)
notInSql
字段 NOT IN ( sql语句 ) 例: notInSql(age, 1, 2, 3, 4, 5, 6) —-> age not in (1, 2, 3, 4, 5, 6) 例: notInSql(id, select id from table where id < 3) —-> id not in (select id from table where id < 3)
groupBy
分组:GROUP BY 字段, …
例: groupBy(id, name) —-> group by id,name
orderByAsc
排序:ORDER BY 字段, … ASC
例: orderByAsc(id, name) —-> order by id ASC, name ASC
orderByDesc
排序:ORDER BY 字段, … DESC
例: orderByDesc(id, name) —-> order by id DESC, name DESC
orderBy
排序:ORDER BY 字段, …
例: orderBy(true, true, id, name) —-> order by id ASC, name ASC
having
HAVING ( sql语句 )
例: having(sum(age) > 10) —-> having sum(age) > 10
例: having(sum(age) > {0}, 11) —-> having sum(age) > 11
并发操作时,我们需要保证对数据的操作不发生冲突。乐观锁就是其中一种方式。乐观锁就是先加上不存在并发冲突问题,在进行实际数据操作的时候再检查是否冲突,我们子啊使用乐观锁时一般在表中增加一个version列,用来记录我们对每天记录操作的版本。每次对某条记录进行过操作对应版本+1,然后我们在每次要进行更新操作时,先查询对应数据的version值,在执行更新时,set version = 老版本 + 1 where version = 老版本,如果在查询老版本号到更新操作的中间时刻有其他人更新了这条数据,这样这次更新语句就会更新失败,这里在更新时对version的操作如果有我们自己做就会显得有些麻烦,所以MP提供了乐观锁插件,使用后我们可以非常方便的对version进行操作
1 2
@Version private Integer version;
1 2 3 4 5 6
@Bean public MybatisPlusInterceptor mybatisPlusOptimisticLockerInterceptor() { MybatisPlusInterceptormybatisPlusInterceptor=newMybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(newOptimisticLockerInnerInterceptor()); return mybatisPlusInterceptor; }