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} }選中你要加注釋的區域,用 ctrl+shift+c 或者 ctrl+/ 會加上 // 注釋,再重復按一下就會去掉 // 注釋。
多行注釋
/**This*my*first*java*/ public class HelloWorld{public static void main(String [] args){System.out.println("HelloWorld");} }選中你要加注釋的區域,用 ctrl+shift+/ 會加上 /…/ 注釋,再用 ctrl+shift+\ 會去掉 /…/ 注釋。(注意:正斜杠是加注釋,反斜杠是去掉注釋)
文本注釋
/***This*is*my*first*java*/ public class HelloWorld{public static void main(String [] args){System.out.println("HelloWorld");} }快捷鍵為:Alt+Shift+J
jsp 的注釋
第一種
<!-- <%=new Date()%> -->注釋中的代碼會執行,但不會在頁面上輸出。
這種格式的注釋快捷鍵:shift+ctrl+c 單行注釋(沒有ctrl+/快捷鍵),shift+ctrl+/ 多行注釋。
這是HTML/XML的原版注釋,會老老實實的發到客戶端的,有什么見不得人的就別用這個寫了
第二種
<%--注釋內容--%>注釋中的代碼不會執行,也不會在頁面上輸出。
這種格式的注釋沒有快捷鍵。
jsp文件沒有文本注釋,你非要說有文本注釋,那也是寫在java代碼片段里面,或者寫在聲明片段里面。
有<%-- --%>的東西都是寫給JSP應用服務器看的,不會發到客戶端的。編譯器將其置之不理,html也無緣與其相見,被應用服務器打入冷宮了。這個注釋感覺比較多余,不知道專門又搞一個這種注釋干什么。
第三種
<% //當行注釋 /** 多行注釋 */ %>css 的注釋
/*這是單行注釋*//*這是多行注釋這是多行注釋這是多行注釋 */js 的注釋
單行注釋
// 這是一行注釋 // 另一行注釋奇葩的單行注釋
這種單行注釋不是很常見,會和 html 內的注釋混淆,不推薦使用。這種注釋后面是不要加 -->,這是和 html 注釋不一樣的地方。
<!- 這是一行注釋,(#^.^#)多行注釋
一般寫在 js 文件的開頭位置,或者寫在聲明函數的前面,用來介紹作者、參數、函數用途等信息
/** 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; }參數變量名與參數說明之間使用連字符 -,會使閱讀更友好:
/*** @param {object} partialState - Next partial state to be merged with state.*/大括號內的object 表示參數的類型,說明該參數是一個對象;partialState 是參數名稱;Next partial state to be merged with state. 這是參數的說明信息。
描述一個對象參數的屬性:
/*** @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 參數是一個對象數組,這個數組中的元素對象包含 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進行注釋,再次使用取消注釋,沒有ctrl+/快捷鍵
多行注釋:使用shift+ctrl+/進行注釋,使用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 的注釋
其實和 xml 的注釋一樣。
<!--這是單行注釋--> <!--這是多行注釋這是多行注釋這是多行注釋 -->總結
以上是生活随笔為你收集整理的MyEclipse for Windows 关于 java、jsp、xml、js、html 等文件的注释快捷键及注释格式介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java的访问控制修饰符_访问权限修饰符
- 下一篇: HH SaaS电商系统的标签系统设计