1. Jingtao project architecture design
1.1 The characteristics of the Internet industry
- High concurrency
- Distributed The number of servers is evenly distributed
- Massive data processing ( Big data direction )
- Security issues : Net loan (11%) Security of transactions ( Blockchain )
1.2 Jingtao project architecture design
2. preparation
2.1 Software :(IDEA、MariaDB【sqlyog】)
2.2 The configuration file
1.pom.xml(springboot——Demo1)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--1.parent The role of labels ***
effect :
1: Resolve version conflicts
2: It's a polymerization project (pom)
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--2.maven coordinate ***
maven Project identification : Group Id/ Project name / Version number be called maven coordinate
effect :
1: In the form of coordinates
2: In local warehouse jar The location of the package is the position of the coordinates ,maven Work performed by coordinate lookup jar
--> <groupId>com.jt</groupId>
<artifactId>springboot_demo01</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot_demo01</name>
<description>Demo project for Spring Boot</description>
<!--3.maven Project configuration information ***
--> <properties>
<!-- It specifies jdk Version information -->
<java.version>1.8</java.version>
<!--
Skip test class packaging
By default, the program package will execute the test class If there is a problem with the test class , The program package fails .
--> <skipTests>true</skipTests>
</properties>
<!--4. rely on
Manual dependencies The dependency is springBoot Highly integrated
springBoot Help you to dynamically generate configuration items , Simplified configuration steps
This configuration is called automated configuration information Open the box : Just import jar Package simple configuration can achieve the corresponding function .
--> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!--5.maven Plug in description
SpringBoot utilize maven Management tools for project packaging / Release / Wait for the operation
The tag must be added with -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- properties explain
1. grammar : k-v structure key=value
2. data type : The default is String data type Don't add extra "" Number
3. Character data type : properties The default encoding format for loading is ISO-8859-1 Therefore, adding Chinese requires character translation .
4. shortcoming : be-all key All have to be edited manually There is no way to reuse So we introduced yml To configure
- YML Profile description
1. grammar K-V structure In writing key:value In essence key=value
key:value In the middle (:+ Space ) Separate
key And key Having a father-child relationship . So pay attention to indents when writing .
YML The default format of configuration files is UTF-8 code So you can edit Chinese directly
- SpringBoot Environment switching problem
# The configuration file , When spring Load when container starts .
spring:
profiles:
active: prod
---
# Define the development environment
spring:
profiles: dev
server:
port: 8080
# To configure redis Node information
redis:
host: 192.168.1.100
port: 6379
# If you need to configure multiple environments, you need to set YML Environment segmentation
---
spring:
profiles: prod
server:
port: 8090
# To configure redis Node information
redis:
host: 10.0.0.1
port: 6379
5.@Value Annotation attribute assignment
explain : because YML The configuration file is generally used to configure the third party's integrated information , If you add business data to YML China is not standardized . It's better to add business operations to properties In file .
@RestController //@ResponseBody Convert the return value to json String use The program will not execute the view parser Go straight back to
//@Controller //String type /moduleAndView
public class RedisController {
/**
* Realize the idea :
* If you can get data from the container , Assign directly to the property . Then decoupling can be achieved
* How to achieve :
* Annotation implementation : @Value("${ Profile's key}")
* expression : spel expression
*/
@Value("${redis.host}")
private String host;
@Value("${redis.port}")
private Integer port;
// If you use RestController The return value is String Type returns the string itself
// If an object is returned Then the result must be that of the object JSON data .
@RequestMapping("/getMsg")
public String getMsg(){
return host + ":" + port;
}
}