标签:
UserService
,错误的命名方式userService、userservice
Test
结尾,如UserServiceTest
HTMLEditor
错误的写法··代码缩进为一个tab(4个空格的长度)。Eclipse默认为4个空格的长度。
类中的属性应设置为私有,通过提供get和set方法实现外部类对私有属性的修改。
如果类中的方法仅供类内部使用应设置为private;如果可以供子类使用应设置为protected;如果是公共方法则应设置为public。
版权信息注释在文件的开头,用于声明代码的版权。使用/**/这样的注释方式。
/*
* Copyright ? 2015 TIAMAES Inc. All rights reserved.
*/
package com.tiamaes.gjds.das.controller;
注释模版如下,Window->Preferences->Java->Code Style->Comments->Files
/*
* Copyright ? ${year} TIAMAES Inc. All rights reserved.
*/
Copyright ? 2015 TIAMAES Inc. All rights reserved.说明如下
版权 2015 天迈科技股份呢有限公司 保留所有权利。
- Inc. 根据公司法组成的股份有限公司
- Co. Ltd 有限责任公司
类注释信息中应包含,类的描述信息,作者信息及版本信息。
/**
* 类描述
* @author 王成委
* @since 1.0
* @see xxx
*/
public class TypeName
注释模版如下,Window->Preferences->Java->Code Style->Comments->Types
/**
* ${todo}
* @author 王成委
* @since 1.0
*/
<p></p>
/**
* Indicates that an annotated class is a "Controller" (e.g. a web controller).
*
* <p>This annotation serves as a specialization of {@link Component @Component},
* allowing for implementation classes to be autodetected through classpath scanning.
* It is typically used in combination with annotated handler methods based on the
* {@link org.springframework.web.bind.annotation.RequestMapping} annotation.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 2.5
* @see Component
* @see org.springframework.web.bind.annotation.RequestMapping
* @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
*/
使用下面的模版
/**
* ${todo}
* ${tags}
*/
/**
* TODO
* @param request
* @throws IOException
*/
@RequestMapping("/ctx")
public void test(HttpServletRequest request) throws IOException
如果类中的方法实现了抽象方法或重写了父类的方法,应在方法上加上@Override
注解。如果要覆盖父类方法的注释可以使用/** */
注释来覆盖父类的注释。
Note
一般方法的注释应写在接口中。
org.springframework.core.io.Resource
/**
* Return a File handle for this resource.
* @throws IOException if the resource cannot be resolved as absolute
* file path, i.e. if the resource is not available in a file system
*/
File getFile() throws IOException;
在实现的方法上使用/**...*/
可以覆盖父类方法的注释。
org.springframework.core.io.AbstractResource
/**
* This implementation throws a FileNotFoundException, assuming
* that the resource cannot be resolved to an absolute file path.
*/
@Override
public File getFile() throws IOException {
throw new FileNotFoundException(getDescription() + " cannot be resolved to absolute file path");
}
使用//
来对变量和属性注释,方法内的代码也使用//
注释
如非必要变量和属性可以不加注释,如果代码内有负责逻辑应使用//
注释加以说明
public ServletContextResource(ServletContext servletContext, String path) {
// check ServletContext
Assert.notNull(servletContext, "Cannot resolve ServletContextResource without ServletContext");
this.servletContext = servletContext;
// check path
Assert.notNull(path, "Path is required");
String pathToUse = StringUtils.cleanPath(path);
if (!pathToUse.startsWith("/")) {
pathToUse = "/" + pathToUse;
}
this.path = pathToUse;
}
标签:
原文地址:http://blog.csdn.net/jaune161/article/details/50552299