這是我的百度空間裡的一篇博文,位址:http://hi.baidu.com/winters1224/blog/item/ebcbb10b701d00f8aa645700.html。原文如下:
設定注釋模闆的入口: Window->Preference->Java->Code Style->Code Template 然後展開Comments節點就是所有需設定注釋的元素啦。現就每一個元素逐一介紹:
檔案(Files)注釋标簽:
/**
* @Title: ${file_name}
* @Package ${package_name}
* @Description: ${todo}(用一句話描述該檔案做什麼)
* @author A18ccms A18ccms_gmail_com
* @date ${date} ${time}
* @version V1.0
*/
類型(Types)注釋标簽(類的注釋):
/**
* @ClassName: ${type_name}
* @Description: ${todo}(這裡用一句話描述這個類的作用)
* @author A18ccms a18ccms_gmail_com
*
* ${tags}
字段(Fields)注釋标簽:
* @Fields ${field} : ${todo}(用一句話描述這個變量表示什麼)
*/
構造函數标簽:
* <p>Title: </p>
* <p>Description: </p>
方法(Constructor & Methods)标簽:
* @Title: ${enclosing_method}
* @Description: ${todo}(這裡用一句話描述這個方法的作用)
* @param ${tags} 設定檔案
* @return ${return_type} 傳回類型
* @throws
覆寫方法(Overriding Methods)标簽:
/* (非 Javadoc)
* <p>Title: ${enclosing_method}</p>
* ${see_to_overridden}
代表方法(Delegate Methods)标簽:
* ${see_to_target}
getter方法标簽:
* @return ${bare_field_name}
setter方法标簽:
* @param ${param} 要設定的 ${bare_field_name}
例子:
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<template
autoinsert="false"
context="constructorcomment_context"
deleted="false"
description="Comment for created constructors"
enabled="true"
id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment"
name="constructorcomment">
/**
* 建立一個新的執行個體 ${enclosing_type}.
*
* ${tags}
*/
</template>
autoinsert="true"
context="settercomment_context"
description="Comment for setter method"
id="org.eclipse.jdt.ui.text.codetemplates.settercomment"
name="settercomment">
* @param ${param} the ${bare_field_name} to set
<template
context="methodcomment_context"
description="Comment for non-overriding methods"
id="org.eclipse.jdt.ui.text.codetemplates.methodcomment"
name="methodcomment">
* 此方法描述的是:
* @version: ${date} ${time}
context="delegatecomment_context"
description="Comment for delegate methods"
id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment"
name="delegatecomment">
* ${see_to_target}
context="filecomment_context"
description="Comment for created Java files"
id="org.eclipse.jdt.ui.text.codetemplates.filecomment"
name="filecomment">
* 檔案名:${file_name}
* 版本資訊:
* 日期:${date}
* Copyright 足下 Corporation ${year}
* 版權所有
context="gettercomment_context"
description="Comment for getter method"
id="org.eclipse.jdt.ui.text.codetemplates.gettercomment"
name="gettercomment">
* ${bare_field_name}
* @return the ${bare_field_name}
* @since CodingExample Ver(編碼範例檢視) 1.0
*/
context="overridecomment_context"
description="Comment for overriding methods"
id="org.eclipse.jdt.ui.text.codetemplates.overridecomment"
name="overridecomment">
/* (non-Javadoc)
* ${see_to_overridden}
context="fieldcomment_context"
description="Comment for fields"
id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment"
name="fieldcomment">
* ${field}:${todo}(用一句話描述這個變量表示什麼)
* @since Ver 1.1
context="typecomment_context"
description="Comment for created types"
id="org.eclipse.jdt.ui.text.codetemplates.typecomment"
name="typecomment">
* 此類描述的是:
* @version: ${date} ${time}
</templates>
autoinsert="false"
context="constructorcomment_context"
deleted="false"
description="Comment for created constructors"
enabled="true"
/**
* 建立一個新的執行個體 ${enclosing_type}.
*
* ${tags}
*/
autoinsert="true"
description="Comment for setter method"
id="org.eclipse.jdt.ui.text.codetemplates.settercomment"
* @param ${param} the ${bare_field_name} to set
context="methodcomment_context"
description="Comment for non-overriding methods"
id="org.eclipse.jdt.ui.text.codetemplates.methodcomment"
* 此方法描述的是:
* @version: ${date} ${time}
context="delegatecomment_context"
description="Comment for delegate methods"
id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment"
* ${see_to_target}
context="filecomment_context"
description="Comment for created Java files"
id="org.eclipse.jdt.ui.text.codetemplates.filecomment"
* 檔案名:${file_name}
* 版本資訊:
* 日期:${date}
* Copyright 足下 Corporation ${year}
* 版權所有
context="gettercomment_context"
description="Comment for getter method"
id="org.eclipse.jdt.ui.text.codetemplates.gettercomment"
* ${bare_field_name}
* @return the ${bare_field_name}
* @since CodingExample Ver(編碼範例檢視) 1.0
*/
</template>
context="overridecomment_context"
description="Comment for overriding methods"
id="org.eclipse.jdt.ui.text.codetemplates.overridecomment"
/* (non-Javadoc)
* ${see_to_overridden}
context="fieldcomment_context"
description="Comment for fields"
id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment"
* ${field}:${todo}(用一句話描述這個變量表示什麼)
* @since Ver 1.1
context="typecomment_context"
description="Comment for created types"
id="org.eclipse.jdt.ui.text.codetemplates.typecomment"
* 此類描述的是:
</templates>
MyEclipse 6.5 代 碼提示的設定
MyEclipse 選擇 Windows ->Preperences ->General ->keys
找到 word completion的快捷鍵 把原alt+/删掉!//必須
把Content Assist 的快捷鍵 改成alt+/ 或者你想改的其他快捷鍵
MyEclipse編碼 設定
Myeclipse安裝後編碼預設是GB18030,一般推薦用UTF-8。如果在導入項目後發現亂碼現象,那是編碼設定設 置不對。
全局編碼設定的方法:ToolBar-->Window-->Preferences-->General-->Workspace-->Text file encoding,設定合适的編碼。
局部編碼 設定:在源碼按右鍵-->General-->Editors-->Test Editors-->Spelling-->Encoding,這裡是設定單個檔案的編碼。
推薦還是 使用全局編碼設定。
MyEclipse設定JSP頁面預設編碼方 式:
windows(視窗)-Preferences(首選項)-MyEclipse-Files & Editors-JSP-右 側encoding:設 置為ISO10646/Unicode(UTF-8)
MyEclipse在Java檔案中設定作 者、日期等說明:
windows(視窗)-Preferences(首選項)-Java-Code Style(代碼樣式)-Code Templates(代碼模版)-右側Comments(注釋)-選擇Types(類型)-點選edit(編輯)-輸入如下資訊
/**
* @包名 ${package_name}
* @檔案名 ${file_name}
* @作者 NoureWang
* @建立日期 ${date}
* @版本 V 1.0
點選OK(确定)-選中左側的代碼樣式-選擇右側複選框(Automatically add Comments for new Methods and types)(自動為新方法和類型添加注釋)-點選Apply(應用)-點選OK(确 定)
eclipse裡面有 一個spell check的開關,把它關了。具體操作windows->preference->輸入spell
自動提示:具體操作 windows->preference->輸入content assist 選擇Java->editor->content assist
Auto activation triggers for Java:後面輸入.abcdefghijklmnopqrstuvwxyz 确定
然後導出。
==========轉載結束=============
為了回報耐心看到這裡的同志哥,補充兩點。
1、用Eclipse導出javadoc時,如果java的編碼方式是utf-8,那麼導出的javadoc中會出現亂碼。這種情況,需要在Eclipse導出javadoc向導的最後一頁的Extra JavaDoc Options 裡填上:-encoding UTF-8 -charset UTF-8。當然,如果是其它編碼方式,就填對應的編碼方式。
2、Eclipse導出javadoc的時候,上文中的很多标簽不會被識别。如@Title,@Packag等。ms是因為javadoc中标準的标簽隻有少數幾個。是哪幾個呢?我記在另一篇部落格裡了……