Java coding Specification
The first letter of each word in the naming conventions class must be capitalized, as shown in figureUserService
Incorrect naming methoduserService、userservice
Test caseTest
End, suchUserServiceTest
If it starts with the abbreviation, the abbreviation should all be in uppercase, as shown in figureHTMLEditor
Incorrect syntax · the class name should contain English letters or numbers, and special character interfaces should not start with I, the first letter of other words should be capitalized and the method name should be able to see the role of the method. Code indentation specification code
The code is indented into a tab (the length of four spaces ). Eclipse has four spaces by default.
Scope
The attributes in the class should be set to private. By providing the get and set methods, the external class can modify the private attributes.
If the methods in the class are for internal use only, they should be set to private; if they can be used by subclasses, they should be set to protected; if they are public methods, they should be set to public.
Annotation specification copyright information Annotation
Note the copyright information at the beginning of the file to declare the copyright of the Code. Use the/***/annotation method.
/* * Copyright ? 2015 TIAMAES Inc. All rights reserved. */package com.tiamaes.gjds.das.controller;
The annotation template is as follows: Window> Preferences> Java> Code Style> Comments> Files
/* * Copyright ? ${year} TIAMAES Inc. All rights reserved. */
Copyright? 2015 TIAMAES Inc. All rights reserved. The description is as follows:
Copyright: 2015 tianmai Technology Co., Ltd. reserves all rights.
-Inc.A joint stock limited company composed of companies under the Company Law
-Co. LtdLimited Liability Company
Class annotation Specification
The description, author, and version information of the class should be included in the class annotation information.
/*** Class description ** @ author Wang Cheng Commission * @ since 1.0 * @ see xxx */public class TypeName
The annotation template is as follows: Window> Preferences> Java> Code Style> Comments> Types
/*** $ {Todo} * @ author Wang Cheng Commission * @ since 1.0 */
Class description:Description class function, which is directly written in a single row. If multiple rows need to be used
@ Author:Multiple authors use multiple @ author
@ Since:Indicates the version from which this class starts.
@ See:Other classes or methods related to Classes
For more information, see org. springframework. stereotype. Controller class annotations.
/** * Indicates that an annotated class is a "Controller" (e.g. a web controller). * *
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 following template
/** * ${todo} * ${tags} */
$ {Tags }:Automatically generate parameters, exceptions, return values, and other annotations
/** * TODO * @param request * @throws IOException */@RequestMapping("/ctx")public void test(HttpServletRequest request) throws IOException
If the methods in the class implement abstract methods or override the methods of the parent class, you should add@Override
Annotation. You can use/** */
Annotation to overwrite the comments of the parent class.
Note
Comments of common methods should be written in interfaces.
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;
Use/**...*/
The comment of the parent class method can be overwritten.
org.springframework.core.io.AbstractResource/** * This implementation throws a FileNotFoundException, assuming * that the resource cannot be resolved to an absolute file path. */@Overridepublic File getFile() throws IOException { throw new FileNotFoundException(getDescription() + " cannot be resolved to absolute file path");}
Comments of attributes and variables and code in the Method
Use//
To comment on variables and attributes. The code in the method is also used.//
Note
Unless necessary variables and attributes are not annotated, use//
Annotations
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;}