MyEclipse for Windows 关于 java、jsp、xml、js、html 等文件的注释快捷键及注释格式介绍
文章目錄
- java 的注釋
- 單行注釋
- 多行注釋
- 文本注釋
- jsp 的注釋
- 第一種
- 第二種
- 第三種
- css 的注釋
- js 的注釋
- 單行注釋
- 奇葩的單行注釋
- 多行注釋
- 文檔注釋
- xml 的注釋
- html 的注釋
java 的注釋
單行注釋
public class HelloWorld{public static void main(String [] args){System.out.println("HelloWorld");//This is my first java} }選中你要加注釋的區(qū)域,用 ctrl+shift+c 或者 ctrl+/ 會(huì)加上 // 注釋,再重復(fù)按一下就會(huì)去掉 // 注釋。
多行注釋
/**This*my*first*java*/ public class HelloWorld{public static void main(String [] args){System.out.println("HelloWorld");} }選中你要加注釋的區(qū)域,用 ctrl+shift+/ 會(huì)加上 /…/ 注釋,再用 ctrl+shift+\ 會(huì)去掉 /…/ 注釋。(注意:正斜杠是加注釋,反斜杠是去掉注釋)
文本注釋
/***This*is*my*first*java*/ public class HelloWorld{public static void main(String [] args){System.out.println("HelloWorld");} }快捷鍵為:Alt+Shift+J
jsp 的注釋
第一種
<!-- <%=new Date()%> -->注釋中的代碼會(huì)執(zhí)行,但不會(huì)在頁面上輸出。
這種格式的注釋快捷鍵:shift+ctrl+c 單行注釋(沒有ctrl+/快捷鍵),shift+ctrl+/ 多行注釋。
這是HTML/XML的原版注釋,會(huì)老老實(shí)實(shí)的發(fā)到客戶端的,有什么見不得人的就別用這個(gè)寫了
第二種
<%--注釋內(nèi)容--%>注釋中的代碼不會(huì)執(zhí)行,也不會(huì)在頁面上輸出。
這種格式的注釋沒有快捷鍵。
jsp文件沒有文本注釋,你非要說有文本注釋,那也是寫在java代碼片段里面,或者寫在聲明片段里面。
有<%-- --%>的東西都是寫給JSP應(yīng)用服務(wù)器看的,不會(huì)發(fā)到客戶端的。編譯器將其置之不理,html也無緣與其相見,被應(yīng)用服務(wù)器打入冷宮了。這個(gè)注釋感覺比較多余,不知道專門又搞一個(gè)這種注釋干什么。
第三種
<% //當(dāng)行注釋 /** 多行注釋 */ %>css 的注釋
/*這是單行注釋*//*這是多行注釋這是多行注釋這是多行注釋 */js 的注釋
單行注釋
// 這是一行注釋 // 另一行注釋奇葩的單行注釋
這種單行注釋不是很常見,會(huì)和 html 內(nèi)的注釋混淆,不推薦使用。這種注釋后面是不要加 -->,這是和 html 注釋不一樣的地方。
<!- 這是一行注釋,(#^.^#)多行注釋
一般寫在 js 文件的開頭位置,或者寫在聲明函數(shù)的前面,用來介紹作者、參數(shù)、函數(shù)用途等信息
/** Author:liaowenxiong* Date:2008-08-10*/文檔注釋
類似于 Java 的文檔注釋
/*** Maps children that are typically specified as `props.children`.** See https://reactjs.org/docs/react-api.html#react.children.map** The provided mapFunction(child, key, index) will be called for each* leaf child.** @param {?*} children Children tree container.* @param {function(*, int)} func The map function.* @param {*} context Context for mapFunction.* @return {object} Object containing the ordered map of results.*/ function mapChildren(children, func, context) {if (children == null) {return children;}var result = [];mapIntoWithKeyPrefixInternal(children, result, null, func, context);return result; }參數(shù)變量名與參數(shù)說明之間使用連字符 -,會(huì)使閱讀更友好:
/*** @param {object} partialState - Next partial state to be merged with state.*/大括號(hào)內(nèi)的object 表示參數(shù)的類型,說明該參數(shù)是一個(gè)對(duì)象;partialState 是參數(shù)名稱;Next partial state to be merged with state. 這是參數(shù)的說明信息。
描述一個(gè)對(duì)象參數(shù)的屬性:
/*** @param {Object} employee - The employee who is responsible for the project.* @param {string} employee.name - The name of the employee.* @param {string} employee.department - The employee's department.*/假如 employee 參數(shù)是一個(gè)對(duì)象數(shù)組,這個(gè)數(shù)組中的元素對(duì)象包含 name 和 department 屬性,那么可以這么描述:
/*** Assign the project to a list of employees.* @param {Object[]} employees - The employees who are responsible for the project.* @param {string} employees[].name - The name of an employee.* @param {string} employees[].department - The employee's department.*/JS 的注釋建議詳見《JavaScript代碼注釋范例》
xml 的注釋
單行注釋:使用shift+ctrl+c進(jìn)行注釋,再次使用取消注釋,沒有ctrl+/快捷鍵
多行注釋:使用shift+ctrl+/進(jìn)行注釋,使用shift+ctrl+\取消注釋。
沒有文本注釋。
xml 注釋:
<error-page> <!--方式1 --> <error-code>500</error-code> <!--方式2 <exception-type>javax.servlet.ServletException </exception-type> --> <location>/error.html</location> </error-page>html 的注釋
其實(shí)和 xml 的注釋一樣。
<!--這是單行注釋--> <!--這是多行注釋這是多行注釋這是多行注釋 -->總結(jié)
以上是生活随笔為你收集整理的MyEclipse for Windows 关于 java、jsp、xml、js、html 等文件的注释快捷键及注释格式介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java的访问控制修饰符_访问权限修饰符
- 下一篇: 人间值得是什么意思