Eclipse中設定作者日期等Java註釋模板

weixin_30639719發表於2020-04-05
  1. 設定註釋模板的步驟:點選選單欄上的Window -->Preferences-->Java-->Code Style -->Code Templates,對右側Comments選項中具體的註釋資訊進行編輯即可。可勾選上自動新增註釋資訊,在生成java檔案時便會自動生成註釋,當然也可以手動插入註釋。設定的介面如下:

    Eclipse中設定作者日期等Java註釋模板
  2. 3

    點選Edit按鈕,進入編輯頁面,全部編輯完成後點選“Apply And Close”即可設定完成,並關閉設定頁面。

    Eclipse中設定作者日期等Java註釋模板
    Eclipse中設定作者日期等Java註釋模板
  3. 4

    下面介紹具體的Comment如何設定:

    1. 點選Comments下的Files可對整個Java檔案進行註釋:包括公司名稱,版權所屬,作者資訊,日期等。

     

    /**  

    * <p>Title: ${file_name}</p>  

    * <p>Description: </p>  

    * <p>Copyright: Copyright (c) 2017</p>  

    * <p>Company: www.baidudu.com</p>  

    * @author shenlan  

    * @date ${date}  

    * @version 1.0  

    */  

  4. 5

    2. 點選Types對類進行註釋:

     

    /**  

    * <p>Title: ${type_name}</p>  

    * <p>Description: </p>  

    * @author shenlan  

    * @date ${date}  

    */  

     

    3. 點選Fields對欄位進行註釋:

     

    /** ${field}*/  

     

    4. 點選Constructors對構造方法進行註釋:

     

    /**  

    * <p>Title: </p>  

    * <p>Description: </p>  

    * ${tags}  

    */  

     

    5. 點選Methods對方法進行註釋:

     

    /**  

     

     * <p>Title: ${enclosing_method}</p>  

     

     * <p>Description: </p>  

     

     * ${tags}  

     

     */  

  5. 6

    6. 點選Overriding Methods對重寫方法進行註釋:

     

    /* (non-Javadoc)  

     

     * <p>Title: ${enclosing_method}</p>  

     

     * <p>Description: </p>  

     

     * ${tags}  

     

     * ${see_to_overridden}  

     

     */

     

    7. Delegate methods對代表方法進行註釋:

     

    /**  

    * ${tags}  

    * ${see_to_target}  

    */

     

    8. Getters對get方法進行註釋:

     

    /**

     

     * @return the ${bare_field_name}  

     

     */

     

    9. Setters對set方法進行註釋:

     

    /**

     

     * @param ${param} the ${bare_field_name} to set  

     

     */

  6. 7

    註釋模板的匯入和匯出:點選Import和Export按鈕即可。

    Eclipse中設定作者日期等Java註釋模板
    END

Java註釋模板的使用

 
  1.  

    在設定模板時如果勾選了自動新增註釋資訊,則在建立Java檔案時會自動生成文件和類的註釋資訊,若沒有勾選,按Shift+Alt+J快捷鍵也可生成。

    Eclipse中設定作者日期等Java註釋模板
  2.  

    在對類中的方法進行註釋是:在方法上方輸入/** 後點選回車,即可生成方法註釋;或將游標放在方法名上,按住Shift+Alt+J快捷鍵也可;或在方法上右擊,source》Generate Element Comment也可生成註釋。

    Eclipse中設定作者日期等Java註釋模板
     
    原文地址:https://jingyan.baidu.com/article/1612d500856cb1e20e1eeed5.html( 感謝作者)
     

轉載於:https://www.cnblogs.com/wzlbigdata/p/8385119.html

相關文章