navigation

[react] Hooks

[Encapsulation 01- Design Pattern] Design principles and factory pattern (simple abstract approach) Adapter pattern Decorator pattern [Encapsulation 02- Design Pattern] Command pattern Enjoy pattern Composite pattern Agent pattern

[React from zero practice 01- background] code split [React from zero practice 02- background] permission control [React from zero practice 03- background] custom hooks [React from zero practice 04- background] docker-compose Deploy React + Egg +nginx+mysql [React From zero practice 05- background] Gitlab-CI using Docker automated deployment

[source code – Webpack01 – precompiler] AST abstract syntax tree [source code – Webpack02 – Precompiler] Tapable [source code – Webpack03] hand written webpack-compiler simple compilation process [source code] Redux React-redux01 [source] Axios [source] vuex [source -vue01] Data reactive and initialize render [source -vue02] Computed responsive – Initialize, access, Update Procedure [source -vue04] Watch Listening properties – Initialize and update [source -vue04] vue. set and vm.$set [source -vue05] vue.extend

[source -vue06] Vue. NextTick and VM.$nextTick [Deployment 01] Nginx [Deployment 02] Docker deployVUE project [Deployment 03] Gitlab-CI

[Data Structures and Algorithms 01] Binary search and sort

[Deep 01] Execution context [Deep 02] Prototype chain [Deep 03] Inheritance [Deep 04] Event loop [Deep 05] Curri Bias function [Deep 06] Function memory [Deep 07] Implicit conversions and operators [Deep 07] Browser caching mechanism (HTTP caching mechanism) [Deep 08] Front-end security [Deep 09] Deep copy [Deep 10] Debounce Throttle [Deep 10] Front-end routing [Deep 12] Front-end modularization [Deep 13] Observer mode Publish subscribe mode Bidirectional data binding [Deep 14] Canvas [Deep 15] webSocket Webpack HTTP and HTTPS CSS- Interview Handwriting Promise Data Structures and Algorithms – Binary Search and Sorting Js Design Patterns – Agents, policies, singletons

/ front-end learn java01 – SpringBoot combat environment configuration and the HelloWorld service [front-end learn java02 – SpringBoot combat] mybatis + mysql implementation song to add and delete [front-end learn java03 – SpringBoot combat] Lombok, log, Java04 -SpringBoot combat deployment [front-end science Java04 -SpringBoot combat] static resources + interceptor + front and back end file upload [front-end science Java05 -SpringBoot combat] common annotates + Redis implementation statistics function [front-end science Java06 -SpringBoot combat] inject + Swagger2 3.0 + unit test JUnit5 [Front-End science Java07 -SpringBoot real World] IOC scanner + transaction + Jackson [front-end science Java08 -SpringBoot real world summary 1-7 Multi-module configuration + Mybatis-plus + single multi-module package deployment

(1) Pre-knowledge

(1) Some words

Batch - by - batch Stalled pratices practice, Look up the parent from Repository property for a key map artifact Surefire is a reliable method to verify in JavaCopy the code

(2) MAC version idea shortcut key record

Command + shift + r 2. Bring up Actions Command + 3 3. Set command + 4. Jump between files Command + e 5. Message prompt Command + 1 6. Control + left mouse button 7. Copy file reference path right mouse button -copy path-copy Reference 8. Shift + TAB - Move TAB 9. Find file - CTRL + h 1. command + k to find the next 2. CTRL + h to find file 3. Set the shortcut key (command +,) => (keyMap) => (search for find) => (add the shortcut key) => (command + f)Copy the code

(3) POM. XML configuration item

  • The packaging type of the project
    • packaging
      • pom jar war
      • The default packaging type is packaging= JAR
  • Pom model version
    • modelVersion
  • Project information
    • The project uniquely identifies groupId, including several fields, such as com.wu7, where com is the domain and WU7 is the domain
    • Project name or module name artifactId
    • Project Version Version
    • Project Name
    • Package Type (package type of a project) Packaging Pom Jar war
    • In general, (package name root) = (groupId) + (artifactId), no duplication allowed
    • packageName = groupId + artifactId
  • The parent projectparent
    • Also include groupId, artifactId, Version, and relativePath
    • relativePath
      • RelativePath is used to specify the relativePath to find the parent project pom.xml
      • The default:../pom.xml
      • Priority:RelativePath > Local Repository > Remote Repository
      • 1. Set a null value that will always be fetched from the repository, not from the local path.Such as < relativePath / >
      • 2. There is no relativePath tag to indicate the relative../pom.xmlTo find the
  • Attribute informationproperties
    • Java version: java.version
    • Compile a character encoding project. Build. SourceEncoding
    • The output character encoding project. Reporting. OutputEncoding
    • Skip Test when packaging <skipTests>true</skipTests>
  • = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = dependencies dependencies
  • compilebuild
    • The plug-in set plugins
    • Plug-in plugin
  • = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = module modules
    • Used in a parent module to indicate a contained (submodule)

(4) jackson

  • Previous nuggets article
  • jackson fastjson gson
  • The installation
    • It is commonly used in Web developmentspring-boot-starter-webThe initiator is already includedjackson
    • If you are not using the starter above, you will need to install it yourselfspring-boot-starter-jsonRely on
      <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-json</artifactId>
      </dependency>
      Copy the code
  • Jackson’s usual notes
    • @JsonFormat
    • @JsonPropertyOrder
    • @JsonProperty
    • @JsonInclude
    • @JsonIgnore
    • @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")– Formatting time, used for class attributes
    • @JsonPropertyOrder(value = {"singer", "album"})– Adjusts the order of attributes for a class
    • @JsonProperty("aaa")– Change the attribute name of the returned data to AAA
    • @JsonInclude(JsonInclude.Include.NON_NULL)– If it contains, the property is not returned. If it contains NULL, the property is not returned
    • @JsonIgnore– The returned property does not include this field
  • @jsonFormat – Formatting time
    • (global configuration) and (@jsonFormat () is configured separately in beans)
    • Date formatting configuration priority (property in bean object @jsonFormat annotation > Global Configuration)
    • @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
Jackson spring: Jackson: date-format: YYYY-mm-dd HH: MM :ss # Global time-zone: GMT+8 #Copy the code
2. Local configuration - @jsonFormat () @data @Builder @allArgsconstructor @noArgsconstructor @Tablename ("music") public class MpMusicBean { Integer id; String name; String album; String singer; @jsonFormat (pattern = "YYYY-MM-DD ") @jsonFormat (pattern =" YYYY-MM-DD ") Priority (Bean Settings > Global Settings) Timestamp startTime; @tableField (value = "endTime") @jsonFormat (pattern = "YYYY-MM-DD HH: MM :ss") Priority (bean Settings > Global Settings) Timestamp endTime; }Copy the code
  • @jsonpropertyOrder – Adjusts the property order
@jsonPropertyOrder (value = {"singer", "album"}) public class MpMusicBean {Integer ID; String name; String album; String singer; {"album": "Qilixiang 112233", "singer":" Jay 112233", "album": "Album ", "singer":" Jay 112233", "album": "Jay Chou, 112233," / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1 "album" : "112233" qi li xiang, / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2},Copy the code
  • @JsonProperty
@jsonProperty ("start") // Jackson changes the name of the property of the returned data @tableField (value = "startTime") // Value is the name of the database field @jsonFormat (pattern = "Yyyy-mm-dd ") // Jackson formatting time, priority (bean Settings > Global Settings) // The final effect of these three annotations: The database in the startTime column data key corresponding to the entity startTime, and then change the return value to star, and format the time Timestamp startTime;Copy the code
  • @JsonInclude
@jsoninclude (jsoninclude.include.non_null) // Jackson, if null is included, this field is not returned. String singer;Copy the code
  • @JsonIgnore
@jsonignore // Jackson returns a value that does not contain the attribute, ignoring the attribute String name;Copy the code

(5) SimpleDateFormat, sring, Timestamp, datetime several relationships

  • Timestamp
    • Timestamp in Java is equivalent to datetime in database
    • Timestamp. ValueOf (String v) Converts String to Timestamp
  • SimpleDateFormat
    • Mainly used to format time
    • new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")Generate the instance, and then call the methods on the instance
@Test void testDate() { Date date = new Date(); // SimpleDateFormat = new SimpleDateFormat(" YYYY-MM-DD HH: MM :ss"); String format = dateformat.format (date); // Call the format() method on the instance instance and return a string log.info("SimpleDateFormat: {}", format); }Copy the code


(2) Configure multiple modules

  • We divide a project into the following modules
    • The parent module
      • 7-react-admin-java-pro
    • The child module
      • mapper
      • service
      • controller
      • common
  • Multi-module configuration – Test project Github repository address

(2.1) Advantages of multiple modules

  • Each module has (high cohesion), easy calibration, debugging, testing

(2.2) Dependencies of modules

Common generally does not rely on any module, Unless the common encapsulation method involves other modules mapper => relies on common Service => relies on common Mapper Controller => relies on common Service mapper Note: 1. You need to delete the (SRC) folder because the parent module does not need to write code. 2. With the exception of the Controller module, all modules are built projectsCopy the code

(2.3) Idea to do related Settings

  • Character encoding Settings:ctrl + ,= >File Encodings= >utf-8
  • Comments to activate:compiler= >annotation processors= >Enable annotation processing

(2.4) Detailed process of multi-module configuration

Module (1) the parent module 1.1 first new father -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 【 create type for springboot project 】 1.2 modify the parent module of pom. The XML, Change the packaging type from JAR to POM, - dependencyManagenment => poM dependencyManagenment => Dependencies => Dependencies => dependencies => dependencies => dependencies => dependencies => dependencies => dependencies => dependencies The parent project's POM.xml automatically generates the (modules) tag, (2) Submodule 2.1 Create modemodule - Mapper Service Controller ---------- (3) Create modemodule - Mapper service controller Unless the common encapsulation method involves other modules. Mapper => Depends on the common Service => Depends on the Common Mapper Controller => Depends on the Common Service mapper (4) 4.1 Configure the dependencies of each module in the pom. XML file. 4.2 groupId is the same for all modules. </groupId> <artifactId> </artifactId> </artifactId> < version > 0.0.1 - the SNAPSHOT < / version > < / dependency > < the dependency > < groupId > org. Springframework < / groupId > <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> </dependencies>Copy the code



(3) the Mybatis – plus

  • The official documentation

(1) Mybatis-plus ( Mapper)

(1.1) Install idea plugin – MyBatisX

  • command + ,choosepluginsSearch,MyBatisXThe installation
  • The advantage is that clicking on the icon can jump directly to the Mapper and XML configuration files

(1.2) Add Maven dependencies

  • Note:Mybatis and JDBC start packages are already included in the Mybatis plus package, so there is no need to install these two packages
    • Contains mybatis – spring – the boot – the starter
    • Contains the spring – the boot – starter – data – JDBC
  • inapplication.ymlThrough filemybatis-plus: xxxCustomize the configuration
    • mapperLocations: The automatic configuration is complete
      • The default is:classpath*:/mapper/**/*.xml, said in theresources/mapper
      • So SQL mapping file, recommended inresrouces/mapperIn the file
    • SqlSessionFactory: it is automatically configured in the container. The underlying layer is the default data source in the container
    • SqlSessionTemplate: Automatically configured in the container
    • @MapperAnnotations are also automatically scanned
      • You are advised to use @mapperscan to scan specified packages. You do not need to use @mapper for batch scanning
<! -- Mybatis plus includes (mybatis-spring-boot-starter) --> <dependency> < the groupId > com. Baomidou < / groupId > < artifactId > mybatis - plus - the boot - starter < / artifactId > < version > 3.4.2 < / version > </dependency>Copy the code

@ MapperScan (1.3) configuration

  • Specify mapper packages to scan, so you don’t have to use @mapper
  • The @mapperscan annotation is (mappe folder path reference)
@springBootApplication @mapPerscan ("com.example.demo.mapper") @mapper public class Application {public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Copy the code

(1.4) Prepare a bean object that is the user class – MybatisPlusUserBean

  • Note note :(entity class name) must be the same as (database table name), otherwise you need to specify the database name
  • So the entity is called MybatisPlusUserBean, so the database name is going to be myBatis_plus_user_Bean
  • @tablename specifies the name of the database table. By default mp will start with the entity name in lower case and connect with _ as the TableName
@Data @Data @Builder @AllArgsConstructor @NoArgsConstructor @Component @TableName("mybatis_plus_user_bean") // @tablename // specifies the name of the database table. By default mp will start the entity name with lowercase, connect with _, Public class MybatisPlusUserBean {private Long id; private String name; private Integer age; private String email; @tablefield (exist = false) // Private String other; }Copy the code

(1.5) Write a mapper –Inheritance BaseMapper

  • Inheriting the extends BaseMapper< Bean object > gives you cruD capability without having to write cruD by hand
  • The bean object must be named the same as the database table
  • For example, if the entity is called MybatisPlusUserBean, the database name would be myBatis_plus_user_Bean
  • You don’t have to write @mapper anymore because @mapperscan is configured
@Mapper
public interface MybatisPlusUserMapper extends BaseMapper<MybatisPlusUserBean> {
}
Copy the code

(1.6) Prepare the database and user tables

  • Note note :(entity class name) must be the same as (database table name)
  • 2. You can also specify the name of the database table by using @tablename. By default mp will start the entity name with a lowercase letter and use _ as the TableName

(1.7) Test whether the configuration is successful

@SpringBootTest @Slf4j public class MybatisPlusUserTest { @Autowired MybatisPlusUserMapper mybatisPlusUserMapper; / / mapper related Test / @ / query Test void getUser () {MybatisPlusUserBean user. = mybatisPlusUserMapper selectById (1); Log.info (" user information {}", user); } @test void addUser() {MybatisPlusUserBean user = new MybatisPlusUserBean(); long a = 11; MybatisPlusUserBean user2 = user.builder().name(" jj2 ").age(200).email("[email protected]").id(a).build(); int status = mybatisPlusUserMapper.insert(user2); Log.info ("Mybatis-plus insert() return {}", status); @test void deleteUser() {int id = 11; int status = mybatisPlusUserMapper.deleteById(id); Void editUser() {MybatisPlusUserBean user = new MybatisPlusUserBean(); long userId = 11; MybatisPlusUserBean user2 = user.builder().name(" jj13000 ").age(3000).email("[email protected]").id(userId) .build(); int status = mybatisPlusUserMapper.updateById(user2); }}Copy the code
  • Mybatis -plus’s mapper queries selectById

  • Mapper insert for MyBatis -plus

  • Mybatisx plugin is shown below

(2) Mybatis-plus ( Service)

(2.1) The above step 1 is testedextends BaseMapper, continue testingextends IService

  • (mapper) is in addition to (BaseMaper) which inherits myBatis-plus.
  • Interface – (Interface) can also inherit myBatis -plus (IService)
  • Implements class – (Implements service) extension (ServiceImpl
    )

(2.2) Write an Interface Service

------- public interface MpIService extends IService<MybatisPlusUserBean> {}Copy the code

(2.3) Write an implementation class

Public class MpIServiceImpl extends ServiceImpl<MybatisPlusUserMapper, MybatisPlusUserBean> implements MpIService { } ------- // extends ServiceImpl<MybatisPlusUserMapper, MybatisPlusUserBean> MybatisPlusUserBean> MybatisPlusUserMapper; MybatisPlusUserMapper; -mpiservice inherits IS and ver. -mpiservice inherits IS and verCopy the code

(2.4) test

@SpringBootTest @Slf4j public class MpIServiceTest { @Autowired MpIService mpIService; @Test void mpIServiceTest() { List<MybatisPlusUserBean> data = mpIService.list(); log.info("{}", data); }}Copy the code

(3) Enable log of Mybatis-plus

Mybatis - plus: configuration: log - impl: org. Apache. Ibatis. Logging. Stdout. StdOutImpl # open mybatis - plus logsCopy the code


(4) SpringBoot single module project packaging and deployment

(4.1) Differences between package and install

  • A package is simply a package
  • In addition to packaging, install installs the packaged package into the Maven repository
  • Note: If (other projects depend on project A), you should use (install) to package project A

packaging

(4.2.1) Single module packaging process

  • If the SpringBoot project has A JSP page, it can only be typed into a WAR package, if not, it can be typed into a JAR package
  • Step (The idea of way )
    • 1. Add the srping Boot package plug-inspring-boot-maven-plugin
    <! <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins>Copy the code
    • 2. Close the project in IDEA, clear the cache, and selectLifecycle= >clean compile packageThere are no dependencies and no packages will be placed in maven repositories
    • 3. After finishing the package, it will generatetargetFolder, there will be.jar
  • Step (use command packaging, do not use idea to operate)
MVN -dmaven.test. Skip -u clean package -d specifies the meaning of the parameter. -d maven.test This command can be executed only if the spring-boot-maven-plugin is requiredCopy the code

(4.2.2) Multi-module packaging process

(1) Copy all the contents of the build tag from the parent module's POM.xml file to the Controller module. If you want to add configuration => mainClass => application mainClass reference path to the build TAB (3), the final build TAB in the controller module will look like this  <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.woow.wu7.Application</mainClass> < span style = "box-sizing: border-box; color: RGB (74, 74, 74); line-height: 22px; font-size: 13px! Important; word-break: inherit! Important;Copy the code

(4.3) If an error occurs during the packaging process: the test fails, you can set the test to be ignored

  • There are two ways to package without test
    • 1. Inpom.xmlTo perform the following configuration
    <properties>
       <skipTests>true</skipTests>
    </properties> 
    Copy the code
    • 2. Add the pluginmaven-surefire-plugin
    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <! -- Skip checks when packing --> <! --> <skip> </skip> </configuration> </plugin>Copy the code

Deploy the jar package

(4.4) Run the JAR package using commands

(1) java-jar 7-react-admin-java-0.0.1- snapshot. jar (2) java-jar 7- React-admin - java-0.0.1-snapshot. jar & // 1. A + (&) at the end indicates that the command is executed in the background. SSH cannot terminate the Java service with (CTRL + C) // 2. Only (closing the command window) will terminate the Java programCopy the code
Active =production Target /7-react-admin- java-0.0.1-snapshot. jar // - Dspring. Profiles. The active = production specified environment variables is / / production environment requires in SRC/main/resources/application - production. The properties File to configure the configuration in the production environment // -d specifies the parametersCopy the code

Persistence (4.5)

  • The difference between nohup and &
    • Not adding & will terminate Java program execution when CTRL + C
    • & runs in the background, but (closing the terminal or SSH window) still terminates Java program execution
    • Nohup + & (close the terminal or window) is still running, that is, persistent operation
Nohup java-jar-dspring.profiles. Active =production target/7-react-admin- java-0.0.1-snapshot. jar >temp.txt &Copy the code

(4.6) View the background running process of a deployed Java project

  • ps -ef | grep java > a.txt
    • Check whether the Java program exists. You can see the PID, PPID, CMD and other information, that is, you can close the related process according to the PID, such as Java
    • psDisplays a process
      • -e Displays all processes
      • The -f full format
    • Grep indicates search
    • Ps – ef | grep Java > a.t xt said will check the Java background process results in a.t xt file

(4.7) Kill the Java process to terminate the Java program running in the background

  • Kill the process,
  • The process ID can passps -ef | grep javaTo view the
  • kill 76619

Deploy the war file

1. If there are multiple modules and you want to deploy them using WAR packages, then 2. First of all, you need to change the controller module's pom.xml (packaging) to (war) 3. Then you need to create (webapp/WEB-INF/web.xml) file 4 in (SRC /main). Then enter the command to packageCopy the code

data

  • Mapper related
    • Mybatis – Plus common operations www.cnblogs.com/l-y-h/p/128…
    • Mybatis – plus insert blog.csdn.net/pipizhen_/a…
  • The service related
    • Tutorial www.jianshu.com/p/bc5e89eb1…
    • Tutorial www.hangge.com/blog/cache/…
  • Why provides mapper will provide service blog.csdn.net/pingfandeha…
  • packaging
    • Multiple modules packaged segmentfault.com/a/119000002…