Service Coding Standards Spring Data JPA's

Roads and other core systems development background Coding Standards Service

1, coded instructions

1) the beginning of the frame design, priority to reduce development costs; thus, removed dao entity class interface implementation classes; therefore, the spelling sql statement adjusted to the service layer.

2) service layer method, any method annotated with @Modifying call dao layer @Transactional must be added, and increases the property rollbackFor = Exception.class

即 @Transactional(rollbackFor = Throwable.class)

All requirements consistent set of business operations, the need for transaction management, also need to add more notes.

3) Delete the unnecessary reference to avoid referring to the error class is optimized away. idea shortcut keys: Ctrl + Alt + O

4) finishing code format, idea shortcut keys: Ctrl + Alt + L; write code section from finishing, to avoid the entire body optimization, code merge conflicts.

2, Log Print

1) http request and response parameters of the printing system unified filter, at the calling end before the system is returned to the front end of the print request parameters and response parameters and time-consuming information; when the abnormality, exception handling mechanism of the system overall, capture and print anomalies information, and a print request to the Senate

2) the information necessary to print, such as calling the method returns the result to print;

The key point for business use, with clear text, business **, ** operation ** execution results and other necessary information

3) the key to perform the printing step, such as short messages, e-mail, push messages, push messages to rocketMq the like;

Easy troubleshooting

4) where abnormalities may occur, print log;

5) perform multiple steps, each step adding log print; especially for the first time on-line!

6) under different conditions, the program branches along different logic points, the print log; if else if .. else; switch case;

7) sql query parameters and printing;

Objective: To facilitate post troubleshoot the problem.

3, the preparation method

1) small but the method thereof: according to the service module, divided; according to different operation, again refinement; each method ideally controlled within 100 lines.

2) Open Transaction Management necessary: ​​consider, "atomicity, consistency, isolation, durability" ", all placed in the same operating method and the @Transactional open transaction manager;

3) simplify the implementation logic program;

4) the implementation of the program do not need to return down;

Avoid too much nested if else if else, or avoid using the else, so change the code looks simple logic

5) written in the business service implementation code layer, Layer Controller for checking only the necessary parameters, the conversion result entity -> vo; case of multiple calls to download a private method ctr layer was extracted single turn of vo.

Objective: each method execution unit is a small, implement a single function.

4, the encapsulated service level code

BaseService<T>

2, BaseServiceImpl <T>, BaseService <T> implementation class

Here ignored 

Consider the problem: Can remove BaseServiceImpl <T>, BaseService <T> two generic class

Guess you like

Origin blog.csdn.net/jiahao1186/article/details/90606795