標籤:des style io os ar 使用 java sp 檔案
在使用Eclipse 編寫Java代碼時,自動產生的注釋資訊都是按照預先設定好的格式產生的。
修改作者、日期注釋格式:開啟Windows->Preferences->Java->Code Style->Code Templates,點擊右邊視窗中的Comments,可以看到有很多選項,我們便可對此注釋資訊模板進行編輯。
如我們希望在一個Java檔案的開頭設定作者資訊、日期資訊。
選擇Types,點擊Edit,將
/**
* @author ${user}
* ${tags}
*/
將${user}刪除,改成你希望顯示的名字;將${tags}刪除,點擊Insert Variable,選擇Date,這樣就會自動產生日期資訊。在你需要添加註釋的地方點擊Sources->Ganarate Element Comment,或者使用快速鍵 Alt+Shift+J ,則 eclipse 自動在該類前面添加註釋。
注釋的規範如下:
檔案注釋標籤:
/**
* <p>Title: ${file_name}</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: LTGames</p>
* @author linrz
* @date ${date}
* @version 1.0
*/
類型注釋標籤(類的注釋):
/**
* <p>Title: ${type_name}</p>
* <p>Description: </p>
* <p>Company: LTGames</p>
* @author linrz
* @date ${date}
*/
欄位注釋標籤:
/** ${field}*/
建構函式標籤:
/**
* <p>Title: </p>
* <p>Description: </p>
* ${tags}
*/
方法標籤:
/**
* <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
*/
覆蓋方法標籤:
/* (非 Javadoc)
* <p>Title: ${enclosing_method}</p>
* <p>Description: </p>
* ${tags}
* ${see_to_overridden}
*/
代表方法標籤:
/**
* ${tags}
* ${see_to_target}
*/
getter方法標籤:
/**
* @return ${bare_field_name}
*/
setter方法標籤:
/**
* @param ${param} 要設定的 ${bare_field_name}
*/
環境說明:
WindowsXP sp3
Eclipse3.6 Helios Release
一、.java 檔案部分
---------------------
eclipse-->windows-->preferences-->Java-->Code Style-->Code Templates-->Code-->New Java files-->單擊[edit]按鈕
在檔案首行,添加如下內容:
Java代碼
${filecomment}
${package_declaration}
/**
* 建立時間:${date} ${time}
* 項目名稱:${project_name}
* @author daniel
* @version 1.0
* @since JDK 1.6.0_21
* 檔案名稱:${file_name}
* 類說明:
*/
${typecomment}
${type_declaration}
${filecomment}
${package_declaration}
/**
* 建立時間:${date} ${time}
* 項目名稱:${project_name}
* @author daniel
* @version 1.0
* @since JDK 1.6.0_21
* 檔案名稱:${file_name}
* 類說明:
*/
${typecomment}
${type_declaration}
或者
Java代碼
${filecomment}
${package_declaration}
/**
* Filename: ${file_name}
* Copyright: Copyright (c)2010
* Company: com
* @version: 1.0
* @since: JDK 1.6.0_21
* Create at: ${date} ${time}
* Description:
*
* Modification History:
* Date Author Version Description
* -----------------------------------------------------------------
* ${date} daniel 1.0 1.0 Version
*/
${typecomment}
${type_declaration}
${filecomment}
${package_declaration}
/**
* Filename: ${file_name}
* Copyright: Copyright (c)2010
* Company: com
* @version: 1.0
* @since: JDK 1.6.0_21
* Create at: ${date} ${time}
* Description:
*
* Modification History:
* Date Author Version Description
* ------------------------------------------------------------------
* ${date} daniel 1.0 1.0 Version
*/
${typecomment}
${type_declaration}
二、.jsp 檔案部分
---------------------
eclipse-->windows-->preferences-->Web-->JSP Files-->Editer-->Templates-->New JSP File-->單擊[edit]按鈕
在檔案首行,添加如下內容:
Java代碼
<%--
建立時間:${date}${time}
創 建 人:daniel
相關說明:
JDK1.6.0_21 tomcat6.0.29 servlet2.5
--%>
<%--
建立時間:${date}${time}
創 建 人:daniel
相關說明:
JDK1.6.0_21 tomcat6.0.29 servlet2.5
--%>
這樣再建立 .java 或 .jsp 檔案時,eclipse 就會為我們自動將注釋寫好。你還可以通過“匯出”、“匯入”功能,把自己的模板匯出來,方便在其他機器上使用。
Eclipse自動產生作者、日期注釋等功能設定