网站添加 备案,网络营销网站设计,汽车销售管理系统,二手车网站模板阿里巴巴 Select 查询命名规范大全
1. 基础命名模式
核心公式#xff1a;动词 名词 限定条件 返回类型部分阿里巴巴常用词示例动词select, find, get, queryselect#xff08;最正式#xff09;名词表名或实体名User, Order, Product限定ByXxx, ByXxxAndYyy, ForXxxById,…阿里巴巴 Select 查询命名规范大全1. 基础命名模式核心公式动词 名词 限定条件 返回类型部分阿里巴巴常用词示例动词select,find,get,queryselect最正式名词表名或实体名User,Order,Product限定ByXxx,ByXxxAndYyy,ForXxxById,ByNameAndStatus返回可省略或加List,Page,CountList,Page,One,Count2. 各种场景的具体命名场景1单条记录查询// 根据ID查询UserDOselectById(Param(id)Longid);UserDOfindById(Param(id)Longid);UserDOgetById(Param(id)Longid);// 根据唯一键查询UserDOselectByUsername(Param(username)Stringusername);UserDOselectByEmail(Param(email)Stringemail);UserDOselectByMobile(Param(mobile)Stringmobile);// 查询单个字段值StringselectNameById(Param(id)Longid);IntegerselectStatusById(Param(id)Longid);场景2列表查询// 查询所有ListUserDOselectAll();ListUserDOfindAll();ListUserDOlistAll();// 条件查询列表ListUserDOselectByStatus(Param(status)Integerstatus);ListUserDOselectByDeptId(Param(deptId)LongdeptId);ListUserDOselectByNameLike(Param(name)Stringname);// 多条件查询ListUserDOselectByStatusAndDeptId(Param(status)Integerstatus,Param(deptId)LongdeptId);ListUserDOselectByCreateTimeBetween(Param(startTime)DatestartTime,Param(endTime)DateendTime);场景3分页查询// 分页查询所有PageUserDOselectPage(PageUserDOpage);// 条件分页查询PageUserDOselectPageByStatus(PageUserDOpage,Param(status)Integerstatus);PageUserDOselectPageByCondition(PageUserDOpage,Param(condition)UserQueryConditioncondition);场景4统计查询// 计数LongselectCount();Integercount();LongcountAll();// 条件计数LongselectCountByStatus(Param(status)Integerstatus);LongcountByDeptId(Param(deptId)LongdeptId);// 存在性检查BooleanexistsByUsername(Param(username)Stringusername);BooleanexistsByEmail(Param(email)Stringemail);场景5Map格式查询// 单条MapMapString,ObjectselectAsMapById(Param(id)Longid);MapString,ObjectselectUserMap(Param(id)Longid);// 列表MapListMapString,ObjectselectListAsMaps();ListMapString,ObjectselectMapsByStatus(Param(status)Integerstatus);ListMapString,ObjectselectAllAsMaps();// 指定字段MapListMapString,ObjectselectIdAndNameAsMaps();ListMapString,ObjectselectSimpleInfoAsMaps();3. 你的业务场景专用命名飞行数据相关查询// 基础查询ListFlightDataDOselectByFlightRecordId(Param(flightRecordId)LongflightRecordId);ListFlightDataDOselectByRecordIdAndType(Param(recordId)LongrecordId,Param(dataType)StringdataType);// Map格式ListMapString,ObjectselectFlightDataAsMaps(Param(flightRecordId)LongflightRecordId);ListMapString,ObjectselectHeightDataAsMaps(Param(flightRecordId)LongflightRecordId);ListMapString,ObjectselectSpeedDataAsMaps(Param(flightRecordId)LongflightRecordId);// 统计LongcountByFlightRecordId(Param(flightRecordId)LongflightRecordId);MapString,ObjectselectStatsByFlightRecordId(Param(flightRecordId)LongflightRecordId);告警规则相关查询// 规则查询ListAlarmRuleDOselectByConfigId(Param(configId)LongconfigId);ListAlarmRuleDOselectEnabledByConfigId(Param(configId)LongconfigId);ListAlarmRuleDOselectByConfigIdAndType(Param(configId)LongconfigId,Param(ruleType)StringruleType);// Map格式ListMapString,ObjectselectRulesAsMaps(Param(configId)LongconfigId);MapString,ListMapString,ObjectselectRulesGroupByType(Param(configId)LongconfigId);告警分析业务查询// 分析相关ListMapString,ObjectselectForAlarmAnalysis(Param(configId)LongconfigId,Param(flightRecordId)LongflightRecordId);ListMapString,ObjectselectAnalysisResult(Param(analysisId)StringanalysisId);PageMapString,ObjectselectAnalysisHistory(Page?page,Param(query)AnalysisQueryquery);4. 阿里巴巴内部特殊命名复杂查询命名// 联表查询ListUserWithDeptDOselectUserWithDeptByUserId(Param(userId)LonguserId);ListMapString,ObjectselectUserJoinDept(Param(deptId)LongdeptId);// 嵌套查询ListUserDOselectWithSubQuery(Param(minOrderCount)IntegerminOrderCount);// 聚合查询MapString,ObjectselectUserStats(Param(deptId)LongdeptId);ListMapString,ObjectselectGroupByDept();// 窗口函数ListMapString,ObjectselectWithRank(Param(deptId)LongdeptId);批量查询命名// IN查询ListUserDOselectByIds(Param(ids)ListLongids);ListUserDOselectByUsernames(Param(usernames)ListStringusernames);// 批量Map查询ListMapString,ObjectselectMapsByIds(Param(ids)ListLongids);MapLong,UserDOselectMapByIds(Param(ids)ListLongids);// 返回Map结构5. 阿里巴巴的命名约定俗成前缀约定// select 系列最规范UserDOselectById(Longid);ListUserDOselectListByStatus(Integerstatus);// find 系列查询语义UserDOfindById(Longid);ListUserDOfindAll();// get 系列获取语义UserDOgetById(Longid);ListUserDOgetAll();// query 系列复杂查询PageUserDOqueryPage(UserQueryquery);ListUserDOqueryByCondition(UserConditioncondition);后缀约定// List - 返回列表ListUserDOselectListByDeptId(LongdeptId);// Page - 返回分页PageUserDOselectPageByStatus(Page?page,Integerstatus);// Count - 返回数量LongselectCountByStatus(Integerstatus);// One - 返回单个UserDOselectOneByUsername(Stringusername);// Map - 返回Map格式MapString,ObjectselectMapById(Longid);ListMapString,ObjectselectMapListByStatus(Integerstatus);6. 实战中的最佳实践原则1保持一致性// ✅ 好统一风格UserDOselectById(Longid);ListUserDOselectByStatus(Integerstatus);PageUserDOselectPage(PageUserDOpage);// ❌ 不好风格混乱UserDOgetById(Longid);ListUserDOfindListByStatus(Integerstatus);PageUserDOqueryPage(PageUserDOpage);原则2方法名自解释// ✅ 好清晰明了ListUserDOselectByDeptIdAndStatus(LongdeptId,Integerstatus);UserDOselectByUsernameAndPassword(Stringusername,Stringpassword);// ❌ 不好模糊不清ListUserDOselectUsers(LongdeptId,Integerstatus);// 参数意义不明UserDOselectUser(Stringparam1,Stringparam2);// 参数名无意义原则3避免过长// ✅ 好适中长度ListUserDOselectByDeptId(LongdeptId);UserDOselectByUsername(Stringusername);// ❌ 不好过长ListUserDOselectAllUserRecordsByDepartmentIdentifier(LongdeptId);// 太长了7. 你的业务完整示例MapperpublicinterfaceFlightDataMapperextendsBaseMapperFlightDataDO{// 基础查询 FlightDataDOselectById(Longid);ListFlightDataDOselectByFlightRecordId(LongflightRecordId);ListFlightDataDOselectByRecordIdAndType(LongrecordId,StringdataType);// Map格式查询 MapString,ObjectselectMapById(Longid);ListMapString,ObjectselectMapsByFlightRecordId(LongflightRecordId);ListMapString,ObjectselectSimpleMapsByRecordId(LongrecordId);// 统计查询 LongcountByFlightRecordId(LongflightRecordId);IntegercountByRecordIdAndType(LongrecordId,StringdataType);MapString,ObjectselectStatsByFlightRecordId(LongflightRecordId);// 存在性检查 BooleanexistsBySeqIdAndRecordId(IntegerseqId,LongflightRecordId);// 分页查询 PageFlightDataDOselectPageByRecordId(PageFlightDataDOpage,LongflightRecordId);PageMapString,ObjectselectMapPageByRecordId(Page?page,LongflightRecordId);// 批量查询 ListFlightDataDOselectBySeqIds(Param(recordId)LongrecordId,Param(seqIds)ListIntegerseqIds);MapInteger,FlightDataDOselectMapBySeqIds(Param(recordId)LongrecordId,Param(seqIds)ListIntegerseqIds);// 业务专用查询 ListMapString,ObjectselectForAlarmAnalysis(LongflightRecordId);ListMapString,ObjectselectHeightDataForAnalysis(LongflightRecordId);ListMapString,ObjectselectSpeedDataForAnalysis(LongflightRecordId);// 扩展查询 ListMapString,ObjectselectWithFlightRecord(LongflightRecordId);ListMapString,ObjectselectDetailByRecordId(LongflightRecordId);}8. 阿里巴巴的黄金法则记住这几点用select开头- 最规范名词用实体名-User,Order,Product条件用ByXxx-ById,ByStatus返回类型可暗示-List,Page,CountMap格式加AsMaps或Map- 可选快速决策树要查什么 ├── 单条记录 → selectById / selectByXxx ├── 多条记录 → selectListByXxx / selectByXxx (返回List) ├── 分页 → selectPageByXxx ├── 统计 → selectCountByXxx / countByXxx ├── 存在 → existsByXxx ├── Map格式 → selectAsMapsByXxx / selectMapByXxx └── 复杂业务 → selectFor[业务场景]ByXxx对于你的selectFlightDataListByRecordId✅ 是阿里巴巴标准命名如果要加关联表建议selectFlightDataWithFlightRecordByRecordId