# 命名

# API 路径命名规则

基于 数据交互格式标准 - API 交互规则 规则, 在路由命名中应用 开发规范 - 路由命名规则 规则,简言之特性如下

  • 路径使用功能/业务描述性命名,例:/user/profile/del/{id}
  • 单词均使用小写方式书写
  • 词组使用 - 符号分隔,例:/config/user-role/list

# 对象、属性命名规则

对于数据接口中输出的对象名,以及对象中的属性等内容,应使用驼峰命名法(Camel Case)

{
  "user_info": {
    "Name": "zhangsan",
    "age": 18,
    "phone_number": "13655555555",
    "admin_type": 1
  }
}{
  "userInfo": {
    "name": "zhangsan",
    "age": 18,
    "phoneNumber": "13655555555",
    "adminType": 1
  }
}

xxx_yyy_zzz 命名格式仅推荐应用于数据库(表名及表字段名)环境

在编程环境中,即使是变量的声明都应尽可能不使用该格式,在自动化语法检查工具中,也有相应的检查/推荐规则:ESLint - "camelcase" 规则 (opens new window),但常量的命名是个例外

// javascript
const MASTER_ADMIN = 1
const STATUS_ENABLED = 1
const STATUS_DISABLED = 2

// java
public static final String STATUS_ENABLED = 1;
public static final String STATUS_DISABLED = 2;
最后更新时间: 7/23/2021, 1:30:15 PM