文章目录
- 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()%> -->
注释中的代码会执行,只是结果并不会在页面上显示出来而已,但是整个注释内容会输出到页面中。
例如:
<!-- <%=new Date()%> -->
会执行JSP表达式,并且将结果、注释符号一起输出到页面中,你查看页面的源码会看到如下的内容:
<!-- Fri May 27 11:59:37 CST 2022 -->
这种格式的注释快捷键: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 的注释一样。
<!--这是单行注释-->
<!--这是多行注释这是多行注释这是多行注释
-->