news 2026/7/7 17:55:12

关于select所有情况,阿里巴巴的命名是咋样的

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
关于select所有情况,阿里巴巴的命名是咋样的

阿里巴巴 Select 查询命名规范大全

1. 基础命名模式

核心公式:动词 + 名词 + 限定条件 + 返回类型

部分阿里巴巴常用词示例
动词select,find,get,queryselect(最正式)
名词表名或实体名User,Order,Product
限定ByXxx,ByXxxAndYyy,ForXxxById,ByNameAndStatus
返回可省略,或加List,Page,CountList,Page,One,Count

2. 各种场景的具体命名

场景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:列表查询

// 查询所有List<UserDO>selectAll();List<UserDO>findAll();List<UserDO>listAll();// 条件查询列表List<UserDO>selectByStatus(@Param("status")Integerstatus);List<UserDO>selectByDeptId(@Param("deptId")LongdeptId);List<UserDO>selectByNameLike(@Param("name")Stringname);// 多条件查询List<UserDO>selectByStatusAndDeptId(@Param("status")Integerstatus,@Param("deptId")LongdeptId);List<UserDO>selectByCreateTimeBetween(@Param("startTime")DatestartTime,@Param("endTime")DateendTime);

场景3:分页查询

// 分页查询所有Page<UserDO>selectPage(Page<UserDO>page);// 条件分页查询Page<UserDO>selectPageByStatus(Page<UserDO>page,@Param("status")Integerstatus);Page<UserDO>selectPageByCondition(Page<UserDO>page,@Param("condition")UserQueryConditioncondition);

场景4:统计查询

// 计数LongselectCount();Integercount();LongcountAll();// 条件计数LongselectCountByStatus(@Param("status")Integerstatus);LongcountByDeptId(@Param("deptId")LongdeptId);// 存在性检查BooleanexistsByUsername(@Param("username")Stringusername);BooleanexistsByEmail(@Param("email")Stringemail);

场景5:Map格式查询

// 单条MapMap<String,Object>selectAsMapById(@Param("id")Longid);Map<String,Object>selectUserMap(@Param("id")Longid);// 列表MapList<Map<String,Object>>selectListAsMaps();List<Map<String,Object>>selectMapsByStatus(@Param("status")Integerstatus);List<Map<String,Object>>selectAllAsMaps();// 指定字段MapList<Map<String,Object>>selectIdAndNameAsMaps();List<Map<String,Object>>selectSimpleInfoAsMaps();

3. 你的业务场景专用命名

飞行数据相关查询

// 基础查询List<FlightDataDO>selectByFlightRecordId(@Param("flightRecordId")LongflightRecordId);List<FlightDataDO>selectByRecordIdAndType(@Param("recordId")LongrecordId,@Param("dataType")StringdataType);// Map格式List<Map<String,Object>>selectFlightDataAsMaps(@Param("flightRecordId")LongflightRecordId);List<Map<String,Object>>selectHeightDataAsMaps(@Param("flightRecordId")LongflightRecordId);List<Map<String,Object>>selectSpeedDataAsMaps(@Param("flightRecordId")LongflightRecordId);// 统计LongcountByFlightRecordId(@Param("flightRecordId")LongflightRecordId);Map<String,Object>selectStatsByFlightRecordId(@Param("flightRecordId")LongflightRecordId);

告警规则相关查询

// 规则查询List<AlarmRuleDO>selectByConfigId(@Param("configId")LongconfigId);List<AlarmRuleDO>selectEnabledByConfigId(@Param("configId")LongconfigId);List<AlarmRuleDO>selectByConfigIdAndType(@Param("configId")LongconfigId,@Param("ruleType")StringruleType);// Map格式List<Map<String,Object>>selectRulesAsMaps(@Param("configId")LongconfigId);Map<String,List<Map<String,Object>>>selectRulesGroupByType(@Param("configId")LongconfigId);

告警分析业务查询

// 分析相关List<Map<String,Object>>selectForAlarmAnalysis(@Param("configId")LongconfigId,@Param("flightRecordId")LongflightRecordId);List<Map<String,Object>>selectAnalysisResult(@Param("analysisId")StringanalysisId);Page<Map<String,Object>>selectAnalysisHistory(Page<?>page,@Param("query")AnalysisQueryquery);

4. 阿里巴巴内部特殊命名

复杂查询命名

// 联表查询List<UserWithDeptDO>selectUserWithDeptByUserId(@Param("userId")LonguserId);List<Map<String,Object>>selectUserJoinDept(@Param("deptId")LongdeptId);// 嵌套查询List<UserDO>selectWithSubQuery(@Param("minOrderCount")IntegerminOrderCount);// 聚合查询Map<String,Object>selectUserStats(@Param("deptId")LongdeptId);List<Map<String,Object>>selectGroupByDept();// 窗口函数List<Map<String,Object>>selectWithRank(@Param("deptId")LongdeptId);

批量查询命名

// IN查询List<UserDO>selectByIds(@Param("ids")List<Long>ids);List<UserDO>selectByUsernames(@Param("usernames")List<String>usernames);// 批量Map查询List<Map<String,Object>>selectMapsByIds(@Param("ids")List<Long>ids);Map<Long,UserDO>selectMapByIds(@Param("ids")List<Long>ids);// 返回Map结构

5. 阿里巴巴的命名约定俗成

前缀约定

// select 系列(最规范)UserDOselectById(Longid);List<UserDO>selectListByStatus(Integerstatus);// find 系列(查询语义)UserDOfindById(Longid);List<UserDO>findAll();// get 系列(获取语义)UserDOgetById(Longid);List<UserDO>getAll();// query 系列(复杂查询)Page<UserDO>queryPage(UserQueryquery);List<UserDO>queryByCondition(UserConditioncondition);

后缀约定

// List - 返回列表List<UserDO>selectListByDeptId(LongdeptId);// Page - 返回分页Page<UserDO>selectPageByStatus(Page<?>page,Integerstatus);// Count - 返回数量LongselectCountByStatus(Integerstatus);// One - 返回单个UserDOselectOneByUsername(Stringusername);// Map - 返回Map格式Map<String,Object>selectMapById(Longid);List<Map<String,Object>>selectMapListByStatus(Integerstatus);

6. 实战中的最佳实践

原则1:保持一致性

// ✅ 好:统一风格UserDOselectById(Longid);List<UserDO>selectByStatus(Integerstatus);Page<UserDO>selectPage(Page<UserDO>page);// ❌ 不好:风格混乱UserDOgetById(Longid);List<UserDO>findListByStatus(Integerstatus);Page<UserDO>queryPage(Page<UserDO>page);

原则2:方法名自解释

// ✅ 好:清晰明了List<UserDO>selectByDeptIdAndStatus(LongdeptId,Integerstatus);UserDOselectByUsernameAndPassword(Stringusername,Stringpassword);// ❌ 不好:模糊不清List<UserDO>selectUsers(LongdeptId,Integerstatus);// 参数意义不明UserDOselectUser(Stringparam1,Stringparam2);// 参数名无意义

原则3:避免过长

// ✅ 好:适中长度List<UserDO>selectByDeptId(LongdeptId);UserDOselectByUsername(Stringusername);// ❌ 不好:过长List<UserDO>selectAllUserRecordsByDepartmentIdentifier(LongdeptId);// 太长了!

7. 你的业务完整示例

@MapperpublicinterfaceFlightDataMapperextendsBaseMapper<FlightDataDO>{// === 基础查询 ===FlightDataDOselectById(Longid);List<FlightDataDO>selectByFlightRecordId(LongflightRecordId);List<FlightDataDO>selectByRecordIdAndType(LongrecordId,StringdataType);// === Map格式查询 ===Map<String,Object>selectMapById(Longid);List<Map<String,Object>>selectMapsByFlightRecordId(LongflightRecordId);List<Map<String,Object>>selectSimpleMapsByRecordId(LongrecordId);// === 统计查询 ===LongcountByFlightRecordId(LongflightRecordId);IntegercountByRecordIdAndType(LongrecordId,StringdataType);Map<String,Object>selectStatsByFlightRecordId(LongflightRecordId);// === 存在性检查 ===BooleanexistsBySeqIdAndRecordId(IntegerseqId,LongflightRecordId);// === 分页查询 ===Page<FlightDataDO>selectPageByRecordId(Page<FlightDataDO>page,LongflightRecordId);Page<Map<String,Object>>selectMapPageByRecordId(Page<?>page,LongflightRecordId);// === 批量查询 ===List<FlightDataDO>selectBySeqIds(@Param("recordId")LongrecordId,@Param("seqIds")List<Integer>seqIds);Map<Integer,FlightDataDO>selectMapBySeqIds(@Param("recordId")LongrecordId,@Param("seqIds")List<Integer>seqIds);// === 业务专用查询 ===List<Map<String,Object>>selectForAlarmAnalysis(LongflightRecordId);List<Map<String,Object>>selectHeightDataForAnalysis(LongflightRecordId);List<Map<String,Object>>selectSpeedDataForAnalysis(LongflightRecordId);// === 扩展查询 ===List<Map<String,Object>>selectWithFlightRecord(LongflightRecordId);List<Map<String,Object>>selectDetailByRecordId(LongflightRecordId);}

8. 阿里巴巴的黄金法则

记住这几点:

  1. select开头- 最规范
  2. 名词用实体名-User,Order,Product
  3. 条件用ByXxx-ById,ByStatus
  4. 返回类型可暗示-List,Page,Count
  5. Map格式加AsMapsMap- 可选

快速决策树:

要查什么? ├── 单条记录 → selectById / selectByXxx ├── 多条记录 → selectListByXxx / selectByXxx (返回List) ├── 分页 → selectPageByXxx ├── 统计 → selectCountByXxx / countByXxx ├── 存在 → existsByXxx ├── Map格式 → selectAsMapsByXxx / selectMapByXxx └── 复杂业务 → selectFor[业务场景]ByXxx

对于你的selectFlightDataListByRecordId

  • ✅ 是阿里巴巴标准命名
  • 如果要加关联表,建议:selectFlightDataWithFlightRecordByRecordId
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/7 5:52:59

12月应季食谱

&#x1f963;南瓜豆腐西红柿蔬菜汤-晚餐&#x1f96c;食材&#xff1a; &#x1f383;贝贝南瓜&#x1f9c8;嫩豆腐&#x1f345;西红柿&#x1f344;木耳&#x1f96c;青菜&#x1f9c2;盐&#x1f336;️白胡椒粉&#x1f372;营养&#xff1a;&#x1f955;南瓜富含β-胡萝…

作者头像 李华
网站建设 2026/7/7 15:28:28

Windows安装Maven

一、什么是 MavenMaven是一个基于POM模型的项目管理和构建自动化工具&#xff0c;其核心是通过一份配置文件&#xff0c;实现依赖管理和标准化的构建流程。对于Java开发者而言&#xff0c;Maven不是一个可选项&#xff0c;而是一个基础设施。它极大地降低了项目管理的复杂度&am…

作者头像 李华
网站建设 2026/7/7 17:26:26

Blender重网格革命:QRemeshify打造完美四边形拓扑的实战指南

Blender重网格革命&#xff1a;QRemeshify打造完美四边形拓扑的实战指南 【免费下载链接】QRemeshify A Blender extension for an easy-to-use remesher that outputs good-quality quad topology 项目地址: https://gitcode.com/gh_mirrors/qr/QRemeshify 在3D建模领域…

作者头像 李华
网站建设 2026/7/7 11:17:18

Ls-dyna聚能爆破研究:聚能射流击穿钢板的二维模型及破坏形式分析

Ls-dyna 聚能爆破.研究聚能射流击穿钢板&#xff0c;本模型为二维模型&#xff0c;研究聚能射流对钢板的破坏形式.可查看聚能射流的应力变化情况聚能射流击穿钢板这玩意儿在军工和采矿领域可是硬核技术。今天咱们用LS-DYNA整点干货&#xff0c;手把手教你怎么用二维模型观察射…

作者头像 李华
网站建设 2026/7/7 13:27:54

传感器学习(day12):宝马夜视系统揭秘:MEMS传感器技术解析

每日更新教程&#xff0c;评论区答疑解惑&#xff0c;小白也能变大神&#xff01;" 目录 第一部分&#xff1a;宝马夜视系统的技术解析与应用实践 1.1 发展历程与战略布局 1.2 核心技术原理&#xff1a;远红外线&#xff08;FIR&#xff09;的选择 1.3 系统功能与性能…

作者头像 李华
网站建设 2026/7/7 18:02:14

3步搞定Inno Setup中文界面:让安装程序说中文的终极指南

3步搞定Inno Setup中文界面&#xff1a;让安装程序说中文的终极指南 【免费下载链接】Inno-Setup-Chinese-Simplified-Translation :earth_asia: Inno Setup Chinese Simplified Translation 项目地址: https://gitcode.com/gh_mirrors/in/Inno-Setup-Chinese-Simplified-Tra…

作者头像 李华