@Service
public class OaMaterialTypeService extends ServiceImpl<OaMaterialTypeMapper, OaMaterialType> {
private void checkTotalNum(String entityUuid) {
long count = lambdaQuery().eq(OaMaterialType::getEntityUuid,entityUuid)
.eq(OaMaterialType::getStatus,StatusEnum.INUSE.getValue())
.count();
if(count >= GlobalConstant.TYPE_MAX_TOTAL_NUM){
throw new IllegalArgumentException("类目总数不能超过"
+String.valueOf(GlobalConstant.TYPE_MAX_TOTAL_NUM)+"个");
}
}
}
在service中直接调用
lambdaQuery(),lambdaUpdate(),
用这个的好处是属性匹配的时候用的实体类的字段,如果字段变更语法检查会自动提示错误,编译的时候也会报编译错误。如果用其他的查询,属性匹配使用的字符串,如果实体类字段变更无法进行错误提示,一个实体类可能会在多个地方被引用,所以用lambda是最佳实践