首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 綜合教學

MyEclipse/Java 代碼模板配置:標準化 Javadoc 註釋模板全集

     編輯:Java 綜合教學

配置入口

Window → Preferences → Java → Code Style → Code Templates → 展開 Comments 節點,逐項編輯下列模板。

標準化註釋模板庫

1. 文件頭註釋

/**
 * FileName: ${file_name}
 * @Description: ${todo}
 * @author: ${user}
 * @version V1.0
 * Createdate: ${date} ${time}
 * Copyright: Copyright(C) ${year}-${year+1}
 * Company: ${company}
 * All rights Reserved, Designed By ${author}
 * Modification History:
 * Date         Author      Version     Description
 * -----------------------------------------------------------------------
 * ${date}      ${user}     1.0         1.0
 * Why & What is modified:
 */

2. 類/接口/枚舉註釋

/**
 * @ClassName: ${type_name}
 * @Description: ${todo}
 * @author: ${user}
 * @date: ${date} ${time}
 */

3. 字段/屬性註釋

/**
 * @Fields ${field} : ${todo}
 */

4. 構造方法註釋

/**
 * @Title: ${enclosing_type}
 * @Description: ${todo}
 * @param: ${tags}
 * @throws
 */

5. 普通方法註釋

/**
 * @Title: ${enclosing_method}
 * @Description: ${todo}
 * @param: ${tags}
 * @return: ${return_type}
 * @throws
 */

6. 覆寫方法註釋

/**
 * <p>Title: ${enclosing_method}</p>
 * <p>Description: </p>
 * ${tags}
 * ${see_to_overridden}
 */

7. 委託方法註釋

/**
 * ${tags}
 * ${see_to_target}
 */

8. Getter 方法註釋

/**
 * @Title: ${enclosing_method} <BR>
 * @Description: ${todo} <BR>
 * @return: ${field_type} <BR>
 */

9. Setter 方法註釋

/**
 * @Title: ${enclosing_method} <BR>
 * @Description: ${todo} <BR>
 * @param: ${tags}
 */

變量說明與技巧

  • ${todo}:光標自動定位處,便於填寫業務描述。
  • ${user}/${date}/${time}:自動填充系統用戶名/日期/時間。
  • ${tags}:自動展開為所有參數的 @param 標簽。
  • ${see_to_overridden}/${see_to_target}:自動生成 @see 引用父類/目標方法。
  • 公司/作者信息建議在 eclipse.ini 中配置 -Duser.name=xxx -Dcompany=xxx 統一管理。

最佳實踐建議

  1. 團隊統一導出:配置完成後 File → Export → Java → Code Style → Code Templates 導出 .xml,納入項目代碼規範倉庫,新成員一鍵導入。
  2. 配合 Save Actions:啟用 Preferences → Java → Editor → Save Actions → Additional actions → Configure → Code Style → Add missing Javadoc tags,保存自動補全缺失標簽。
  3. Checkstyle 強制執行:在 CI 流水線集成 Checkstyle,檢查 Javadoc 完整性,杜絕「無註釋提交」。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved