[SpringBoot2.X] SpringBoot a learning summary

 

This article Mu class network "version of the 2019 SpringBoot2.x to build enterprise-class micro-channel ordering system," a summary of the study notes for future review

The course addresses: https: //coding.imooc.com/class/117.html

 

1. Course technology stack: micro letter to SpringBoot and characteristics as the core technology stack

Back-end technology include: SpringBoot2.x, JPA, MyBatis, Freemarker, WebSocket, Redis-based caching implemented, distributed Session, distributed lock

Micro-channel features include: micro-channel scan code to log (need Qualification account), micro-letter web page authorization (micro-channel public number develop test account can, you need to network penetration tools), micro-channel payments and refunds (need Qualification account)

Software Version: SpringBoot2.1.4, JDK1.8

Prior to development projects, the need for a detailed analysis of the project design ---- sub role, function modules, deployment architecture, database tables, and other dimensions of analysis and design! ! !

2. New SpringBoot project, by "Spring Initializr" create, then you can complete all the way next to relevant when required jar package can be introduced pom.

 

Use a common jar package routines: pom introduced dependence - Configuration> application.yml in -> tags used

 

3. pom jar package commonly introduced

spring-boot-starter- * starting rely: is at the core of SpringBoot, which provides one-stop Spring and related technical services, so developers no longer concerned about the Spring configuration, simplifies the traditional dependency injection procedure.

Log: slf4j + logback

Lombok: Lombok can reduce write a lot of code duplication. For example, the preparation method of getter / setter / toString etc.

 

4. Profiles

application.yml: unified configuration and management of the project by the profile. Note: This file can be configured with a simple log

logback-spring.xml: log can configure complex. Create logback-spring.xml file in the resources folder, and wherein the configuration log output format and content, springBoot automatically reads the configuration file

The Design and Development of the order

   API documentation -> entity classes -> the DAO layer (Dao interface unit test) -> Layer-Service (Service interface and its implementation class, unit testing) -> the Controller layer

   Dao through unit testing and development layer Service layer

6. entity classes developed based JPA

    When creating an entity class, the class name and attribute names are used hump nomenclature, Jpa automatically converted; and add @Entity annotate entity classes; primary key increment added @GeneratedValue (strategy = GenerationType.IDENTITY) notes, otherwise it will report 'relationship. " hibernate_sequence "does not exist 'error; Note @DynamicInsert (), @ DynamicUpdate ()

JPA-based layer 7. Development Dao

    When you create a dao layer interface, the interface inherits from JpaRepository

After the annotation with the @Transactional 8. performs rollback unit test, to keep clean the database table data

9. write Service interface and its implementation class.

  • All business logic into the Service layer implementation

10. DTO: Data transfer object, designed to transfer data between the layers

  • Between the layers preferably used to transfer data DTO objects

 

 11. API documentation and unified format VO return

a. Code did not move, the document first

b. --VO returned to the front end of the package

. C return the object to create a unified front-end: ResultVO, only need to return to the front of the field, in principle, the direct return information for the entity classes because of security concerns

 

 12. Form Validation

 13. Use freemarker, Controller needs to return the object ModelAndView

 14. Several custom exception classes (to be inherited from RuntimeException), abnormal development of the entire process if an exception is thrown directly without having to deal, finally unified global exception handler

 

Guess you like

Origin www.cnblogs.com/xsjs/p/11098669.html