Naming specification Class naming conventions
- The first letter of each word in the class needs to be capitalized, for example
UserService
, to name the wrong wayuserService、userservice
- Test cases
Test
End with, for example,UserServiceTest
- If you start with a term abbreviation, the term abbreviation should be capitalized, such as
HTMLEditor
the wrong wording ·
- Class names should use English letters or numbers, and special characters should not appear
- interface does not start with I
Method Naming conventions
- First letter lowercase, other words first uppercase
- It should be possible to see how the method works in terms of method names
Coding Specification Code Indentation
The code indents to one tab (4 spaces in length). Eclipse defaults to a length of 4 spaces.
Scope
The properties in the class should be set to private, and the external class is modified by providing the get and set methods for the private property.
Why use get and set accessors
If the method in the class is intended for use within the class, it should be set to private, if it should be set to protected, and if it is public, it should be set to publicly.
Comment Specification Copyright Information note
The copyright information note at the beginning of the file is used to declare the copyright of the code. Use annotation methods such as/**/.
/* * Copyright ? 2015 TIAMAES Inc. All rights reserved. */package com.tiamaes.gjds.das.controller;
The comment template is as follows, Window->preferences->java->code Style->comments->files
/* * Copyright ? ${year} TIAMAES Inc. All rights reserved. */
Copyright? Tiamaes INC. All rights reserved are described below.
Copyright 2015 days Mai Technology shares limited all rights reserved.
- Inc. incorporated under the company law
- Co. Ltd Limited Liability Company
Class Annotation Specification
The class annotation information should contain the description information of the class, the author information and the version information.
/** * 类描述 * @author 王成委 * @since 1.0 * @see xxx */publicclass TypeName
The comment template is as follows, Window->preferences->java->code Style->comments->types
/** * ${todo} * @author 王成委 * @since 1.0 */
- Class Description: describes the function of the class, one-line direct write, if multiple lines need to use
<p></p>
- @author: multiple authors use multiple @author
- @since: Description This class starts with that version
- @see: Other classes or methods associated with the class
can refer to the Org.springframework.stereotype.Controller class comment information.
/** * 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 */
Method Comment
Use the template below
/** * ${todo} * ${tags} */
- ${tags}: automatically generate annotations such as parameters, exceptions, return values, etc.
/** * TODO * @param request * @throws IOException */@RequestMapping("/ctx")publicvoidtestthrows IOException
If a method in a class implements an abstract method or overrides a method of a parent class, you should add annotations to the method @Override
. If you want to override a comment for a parent class method, you can use a /** */
comment to overwrite the parent class's comment.
Note
Comments in the general method should be written in the interface.
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 */throws IOException;
Use /**...*/
annotations that can override the parent class method on the implemented method.
org.springframework.core.io.AbstractResource/** * This implementation throws a FileNotFoundException, assuming * that the resource cannot be resolved to an absolute file path. */@OverridepublicgetFilethrows IOException { thrownew" cannot be resolved to absolute file path");}
Comments on attributes and variables and in-method code
Use //
to annotate variables and attributes, and code within methods to use //
annotations
If the non-essential variables and attributes can be commented out, if the code has the responsible logic should be explained by using //
annotations
publicServletContextResource(ServletContext servletContext, String path) { // check ServletContext "Cannot resolve ServletContextResource without ServletContext"); this.servletContext = servletContext; // check path "Path is required"); String pathToUse = StringUtils.cleanPath(path); if (!pathToUse.startsWith("/")) { "/" + pathToUse; } this.path = pathToUse;}
Java Coding Specification