The basic ability of back-end development and the introduction of the mainstream development framework of Java

Preface: Java language development to the back-end, you must understand some things in the mainstream of the back-end, and encourage each other.

 

Back-end development requires the following basic capabilities :

1. Programming language: proficiency in at least one programming language, such as Java, Python, Ruby, PHP, C#, etc.

2. Data structure and algorithm: Possess a solid data structure and algorithm foundation, and be able to flexibly use common data structures and algorithms to solve problems.

3. Database: Understand common database systems, such as MySQL, Oracle, SQL Server, etc., and be able to operate and manage databases proficiently.

4. Network protocols and communication: understand common network protocols, such as HTTP, TCP/IP, etc., and be familiar with commonly used network communication methods and technologies, such as RESTful API, WebSocket, etc.

5. Operating system: Know at least one operating system, such as Linux, Windows, etc., and be able to use command line tools proficiently and perform system configuration.

6. Version control: Understand common version control tools, such as Git, SVN, etc., and be able to use them proficiently for code management and collaborative development.

7. Security: Understand common web security issues and preventive measures, such as SQL injection, XSS attack, CSRF attack, etc.

8. Distributed system: Understand the basic principles and common technologies of distributed systems, such as distributed cache, message queue, load balancing, etc.

9. Software engineering: Understand the basic knowledge of software engineering, such as requirements analysis, design patterns, refactoring, etc., and be able to perform high-quality code writing and system design.

10. Communication and coordination: Possess good communication and coordination skills, and be able to communicate and coordinate effectively with team members, users and other relevant personnel.

 

 

The basic frameworks that need to be understood for back-end development include:

Spring: One of the most popular open source frameworks in the Java field, providing a series of components and tools required for enterprise-level development, such as IoC container, AOP, transaction management, Web framework, etc.

Django: One of the most popular open source frameworks in the Python field, providing efficient, flexible and secure web development solutions, including ORM, template engine, routing, forms, etc.

Ruby on Rails: One of the most popular open source frameworks in the Ruby field, it provides a way to quickly develop web applications with efficient, simple, and elegant features, such as MVC architecture, Active Record, RESTful API, etc.

Flask: A micro-framework in the Python field, providing a simple and flexible web development framework, including routing, template engine, ORM, etc.

Express: One of the most popular web application frameworks in the Node.js field, which provides a series of scalable middleware and routing components to help developers quickly build high-performance web applications.

Laravel: One of the most popular web application frameworks in the PHP field, providing efficient, safe, and maintainable web development solutions, including ORM, routing, and template engines.

Gin: One of the web frameworks in the Go language field, which provides high-performance and high-efficiency web development solutions, including routing, middleware, and template engines.

The above frameworks are relatively popular back-end development frameworks in the industry. Mastering one or more of them can quickly and efficiently complete the back-end development work.

Taking Java language development as an example, introduce Spring, SpringMVC, SpringBoot, MyBatis, Swagger, transaction management, routing, forms, middleware and other knowledge points

 

1.Spring 

Spring is an open source Java framework, which has become one of the most widely used frameworks in Java development due to its lightweight, convenience and scalability. The Spring framework consists of multiple modules, the core of which is the Spring Core module, which provides basic functions such as IoC container, AOP, and event-driven.

In Spring development, Spring Boot is usually used to quickly build applications. Spring Boot is a rapid development framework based on the Spring framework. It provides out-of-the-box configuration, automated dependency management, and pluggable Spring application functions, making Spring application development easier and more efficient.

Some common techniques and tools in Spring development include:

Spring MVC: A web framework based on the MVC design pattern for building web applications.

Spring Data: A framework for simplifying data access, supporting various types of data storage, including relational databases, NoSQL databases, graph databases, etc.

Spring Security: A framework for authentication and authorization that provides role-based access control, single sign-on, encryption, and more.

MyBatis: An open source persistence framework for mapping Java objects to database tables.

Maven: A tool for building, packaging, and publishing Java applications that automates dependencies and the build process.

IntelliJ IDEA: A commonly used Java integrated development environment, which provides a wealth of development tools and plug-ins, which can greatly improve development efficiency.

The above are some common technologies and tools in Spring development, and their use can help developers develop Spring applications more efficiently.

Before SpringMVC and MyBatis appeared

The development of background server mainly depends on JSP/Servlet technology. JSP/Servlet is a Java Web development technology, which realizes the development of Web applications through the mixed writing of Java code and HTML tags. In JSP/Servlet technology, Servlet is a Java class used to handle HTTP requests and responses. By inheriting or implementing the Servlet interface, developers can customize the Servlet class and rewrite its doGet(), doPost() and other methods to handle HTTP requests and responses. JSP is a technology that embeds Java code in HTML, which can be used to dynamically generate Web pages. In JSP/Servlet technology, use JDBC or directly use SQL statements for database operations. JDBC is a Java API for connecting and manipulating databases. Through JDBC, developers can use Java code to execute SQL statements and return the results to Web applications. Although JSP/Servlet technology is no longer the mainstream Java Web development technology, it is still widely used in the development of some small Web applications. For large-scale web applications, technologies such as SpringMVC and MyBatis have become more popular choices, which can greatly improve development efficiency and application scalability.

 

SpringMVC

Spring and SpringMVC are two different frameworks. Although they are both part of the Spring framework, their functions and usage scenarios are different. The Spring framework is an object-oriented framework that can help developers build enterprise-level applications. It provides features such as IoC (Inverse of Control, Inversion of Control) and AOP (Aspect Oriented Programming, aspect-oriented programming), which enables developers to It is easier to manage dependencies between objects and dynamically add aspects while the program is running. SpringMVC is a web framework based on the Spring framework, and it is also an MVC framework. SpringMVC provides a flexible and modular web development experience that can help developers quickly develop web applications. The core components of SpringMVC include DispatcherServlet, Controller, HandlerMapping, ViewResolver and ModelAndView, etc., through which the distribution, processing and response of requests can be realized. Therefore, the difference between the Spring framework and the SpringMVC framework is that the former is an object-oriented framework that provides features such as IoC and AOP, while the latter is a Web framework that provides support for the MVC architectural pattern and can help developers quickly develop Web applications. .

SpringMVC is a web framework based on the Spring framework, which is a web framework of the MVC (Model-View-Controller) architectural pattern. SpringMVC can help developers quickly develop web applications and provides a flexible and modular web development experience. The advantages of SpringMVC include:

Highly modular: The coupling degree between various modules of SpringMVC is low, and developers can freely assemble modules according to their needs.

Flexible configuration method: The configuration method of SpringMVC is very flexible, and can be configured by using annotations, XML configuration files, etc.

Easy to integrate: SpringMVC can be integrated with other frameworks (such as Spring, Hibernate, etc.) to provide a complete web development solution.

Easy to test: The code structure of SpringMVC is clear, and it is easy to perform unit testing and integration testing.

Perfect exception handling mechanism: SpringMVC provides a perfect exception handling mechanism, which can handle exceptions uniformly and improve the robustness of web applications.

The core components of SpringMVC include:

DispatcherServlet: The core component that distributes requests to the Controller.

Controller: A component that processes requests and returns responses.

HandlerMapping: Manage the components of the Controller and map the request to the corresponding Controller.

ViewResolver: Returns the corresponding view component according to the request.

ModelAndView: the encapsulation of the data model and view information returned by the Controller. In general, SpringMVC is an excellent web framework with excellent flexibility, ease of use and scalability, and is an indispensable part of modern web application development.

 

SpringBoot

SpringBoot and SpringMVC are two different frameworks

SpringBoot is an out-of-the-box framework based on the Spring framework that can help developers quickly build Spring applications. SpringBoot provides features such as automatic configuration and executable JAR packages, which can greatly simplify the development and deployment process of Spring applications. Therefore, the difference between SpringBoot and SpringMVC is:

Automatic configuration: SpringBoot has the feature of automatic configuration, which can be automatically configured according to the needs of the application. And SpringMVC needs to be configured manually.

Out of the box: SpringBoot can quickly build a complete Spring application, while SpringMVC is just a web framework.

Microservices: SpringBoot can be used to build microservice applications, while SpringMVC is not a framework specifically for building microservices.

Simplify development: SpringBoot can greatly simplify the development and deployment process of Spring applications, while SpringMVC requires manual configuration and deployment. In general, both SpringBoot and SpringMVC are excellent frameworks that can help developers quickly develop applications, but their usage scenarios and characteristics are different. If you need to quickly build a complete Spring application, then SpringBoot is a good choice; if you only need to build a web application, then SpringMVC is a very good choice.

 

2. MyBatis

MyBatis is a Java persistence framework that helps developers use SQL databases in Java applications. It supports a variety of relational databases, including MySQL, Oracle, PostgreSQL, and SQL Server, among others. The main advantages of MyBatis are its simplicity, flexibility and extensibility. In back-end development, the main role of MyBatis is to map Java objects to data in database tables. Here are some steps for backend development with MyBatis:

Define the data model: First, you need to create Java objects to represent the data in the database. These Java objects should correspond to the columns in the database table, so that the Java objects can be mapped to the data in the database table.

Create a mapping file: MyBatis uses XML files to define the mapping relationship between Java objects and database tables. These mapping files contain SQL statements and parameter mappings, as well as mapping rules between Java objects and database tables.

Configure the data source: Before using MyBatis, you need to configure the data source to connect to the database. Data sources can be configured using JNDI data sources, Java Database Connectivity (JDBC) data sources, or other data sources.

Writing SQL queries: The SQL statements defined in the mapping file can contain various query operations, such as SELECT, UPDATE, DELETE, and INSERT. These query operations can use dynamic SQL to build complex query statements.

Call MyBatis API: Finally, call the MyBatis API in the Java application to execute the SQL query. MyBatis API includes classes such as SqlSession, SqlSessionFactory, and Mapper, which can help developers execute SQL queries and manage database connections. In short, MyBatis is a very powerful Java persistence framework that can help developers easily map Java objects to data in database tables. In back-end development, MyBatis can greatly simplify database operations, improve development efficiency and code quality.

 

3. Spring Cloud Dependency Injection

Spring Cloud is a framework for building and deploying microservice-based applications. It provides a set of tools and libraries for building distributed systems and helps developers implement common patterns and best practices for developing cloud-native applications. Some of the key features of Spring Cloud include service discovery and registration, load balancing, circuit breaking, distributed tracing, and configuration management. It also integrates with other popular open source projects such as Netflix OSS, Docker, and Kubernetes. Built on top of the popular Spring Framework, SpringCloud provides a powerful and flexible platform for developing scalable and resilient cloud-native applications.

SpringCloud uses dependency injection to achieve decoupling between microservices. In the Spring Framework, dependency injection is a way to implement IOC (Inversion of Control, inversion of control). Through IOC, the control of object creation, initialization, and destruction is transferred from the caller to the container, making the application more flexible, scalable, and reusable. In Spring Cloud, each microservice is an independent application, and they need to call and cooperate with each other. SpringCloud uses dependency injection to resolve dependencies between microservices. By injecting dependent objects between microservices, Spring Cloud can automatically assemble and manage the life cycle of these objects at runtime, thereby realizing the decoupling between microservices. Spring Cloud uses the dependency injection mechanism of Spring Framework to inject dependent objects into microservices through annotations or XML configuration. These dependent objects can be other microservices, database connections, message queues, caches, etc. SpringCloud will automatically manage their creation, initialization, and destruction processes, thereby realizing the decoupling between microservices.

 

Does the decoupling of back-end modules use dependency injection?

Yes, dependency injection is a common way of decoupling, and it is also a common technique for decoupling back-end modules. Dependency injection achieves decoupling by handing over the creation and management of objects to the container, so that the modules are no longer tightly coupled, and the maintainability and scalability of the code are improved. In backend modules, dependency injection is often used to achieve decoupling between modules. For example, when a module needs to call the function of another module, the interface of the required module can be injected into the calling module through dependency injection, so as to realize the decoupling between modules. In this way, when a module needs to be modified or replaced, only the corresponding interface implementation needs to be modified or replaced without modifying the code of the calling module, thereby improving the maintainability and scalability of the code. Dependency injection can also be implemented through configuration files or annotations, making it easier for developers to manage object dependencies. In the backend module, commonly used dependency injection frameworks include Spring Framework and Google Guice, etc. These frameworks can help developers implement dependency injection, thereby decoupling back-end modules.

 

4. Use of Swagger annotations

Swagger is an open source framework for designing, building, documenting and consuming RESTful web services. It provides a set of tools to easily create and maintain API documentation, as well as automatically generate client-side and server-side code. In back-end development, Swagger can be used to define API input and output parameters, request and response formats, error codes and other information, making the API easier to use and understand. Swagger can also display the basic information of the API, request parameters, response results, etc. through the UI interface, which is convenient for developers to test and debug. In back-end development, Swagger can be integrated into common frameworks such as Spring Boot and Node.js, bringing great convenience to API development and management.

When using Swagger to build API documents, some annotations can be used to describe the information of the interface. The following are some commonly used Swagger annotations:

@Api: Information used to describe the entire API, including title, description, version, etc.

@ApiOperation: Information used to describe a single interface, including interface name, interface description, request method, etc.

@ApiParam: Used to describe the parameters in the interface, including parameter name, parameter type, whether it is required, description, etc.

@ApiModel: Used to describe the data model, including model name, description, fields, etc.

@ApiModelProperty: Used to describe the fields in the data model, including field names, data types, descriptions, etc.

@ApiResponse: Used to describe the response information of the interface, including response code, response message, response data, etc.

@ApiResponses: Multiple response information used to describe the interface.

@ApiIgnore: Used to ignore an interface or model, not displayed in the document. The above annotations can be used in the back-end code, and the API documentation is automatically generated through the analysis and scanning of Swagger.

5.Redis

Redis in back-end development is an open-source in-memory database that supports multiple data structures and provides a wealth of operation commands. Redis is known for its high speed, high concurrency, and high reliability, and is often used in scenarios such as caching, message queues, counters, session management, and real-time data analysis. Compared with traditional relational databases, Redis has higher performance and lower latency when processing large amounts of data, and is especially suitable for scenarios that require fast reading and writing of data. Redis also supports data persistence, which can save data to the hard disk to ensure data security and recoverability. In back-end development, Redis is widely used in various systems, such as web applications, mobile applications, games, etc.

Taobao uses Redis for a large number of orders mainly to improve the performance and efficiency of order processing. The specific steps are as follows:

Order generation: After the user places an order, the order information will be saved in the MySQL database.

Write to Redis cache: Write order information into Redis cache to speed up order reading and reduce the pressure on MySQL database.

Order query: When order query, the order information is first read from the Redis cache, and if it does not exist in the cache, it is read from the MySQL database.

Data update: If the order status changes, such as payment or delivery, update the order status to the MySQL database and Redis cache.

Distributed lock: In order to prevent multiple threads from modifying the same order at the same time, it is necessary to use a distributed lock, such as the distributed lock implemented by Redis, to ensure data consistency and reliability.

Redis cluster: In order to support high concurrency and high availability, Redis cluster can be used to expand the capacity of Redis cache and improve the availability of Redis.

 In short, Taobao uses Redis for a large number of orders mainly to improve the performance and efficiency of order processing. By saving the order information in the Redis cache, it reduces the pressure on the MySQL database. At the same time, it uses distributed locks to ensure data consistency and reliability. Use Redis cluster to expand the capacity of Redis cache and improve the availability of Redis.

The specific implementation process of distributed locks is as follows:

Acquiring a lock: When a process needs to acquire a lock, it sends a SETNX command to Redis. If the return value is 1, it means that the lock has been successfully acquired. Otherwise, it means that the lock has been acquired by other processes, and the current process needs to continue to wait.

Set expiration time: In order to avoid deadlock and multiple processes holding locks at the same time, it is necessary to set an expiration time for the lock. After successfully acquiring the lock, you need to send another EXPIRE command to set an expiration time for the lock to ensure that the lock will be automatically released within a certain period of time. Even if the process that acquires the lock crashes or is killed unexpectedly, the lock can be automatically released to avoid The lock is held permanently.

Release the lock: When the process no longer needs the lock, it needs to send a DEL command to release the lock, and at the same time notify other processes that the lock has been released, and other processes can try to acquire the lock again.

Use Lua script: In order to avoid the race condition between acquiring the lock and setting the expiration time, you can use the Lua script provided by Redis to realize the atomic operation of acquiring the lock and setting the expiration time to ensure the correctness and reliability of the lock.

 In short, the specific implementation process of distributed locks includes acquiring locks, setting expiration times, releasing locks, and using Lua scripts to implement atomic operations. Setting expiration times and releasing locks are important steps to ensure the correctness and reliability of locks. Using Lua scripts can avoid problems caused by race conditions

 

 

6. Transaction management

In backend development, transaction management is a very important part. A transaction is a collection of operations that either all succeed or all fail. In database operations, transaction management is often used to ensure the integrity and consistency of the database. In backend development, we usually use database transactions to manage operations. In a transaction, a set of database operations is considered a single unit of execution. If any one of these operations fails, the entire transaction will be rolled back to its original state. This ensures data integrity and consistency. When using transactions, you need to pay attention to the following points:

Transactions should be as short as possible to reduce locking time and resource usage.

In a transaction, you should try to avoid long query operations to avoid locking.

Operations should use appropriate isolation levels to avoid concurrency issues.

After the operation is completed, the resource should be released in time. Transaction management is an important part of back-end development, and requires developers to have certain database knowledge and experience to ensure data integrity and consistency.

 

7. Middleware

In backend development, middleware refers to a set of handlers that sit between the client and the server. Middleware can be used to process requests, respond or perform other tasks. Middleware is usually powered by web frameworks such as Express.js, Flask, Django, etc. Here are some common middleware functions:

Routing: Middleware can determine which request handler should be called based on the URL and HTTP method of the request.

Authentication and Authorization: Middleware can be used to authenticate users and authorize access to resources.

Logging: Middleware can be used to log requests and responses for easy debugging and monitoring.

Error handling: Middleware can be used to handle errors in requests and responses, such as 404 Not Found, 500 Internal Server Error, etc.

Caching: Middleware can be used to cache response results to improve application performance. In web frameworks, middleware is usually executed sequentially. Each middleware can process the request and response and pass control to the next middleware. Middleware can modify the request and response objects, and can also decide whether to pass control to the next middleware. If the middleware decides not to pass control, request processing stops and a response is returned. Redis can be used as middleware such as cache, message queue, task queue, etc.

 When using middleware, you need to pay attention to the following points:

The order of middleware is important, different order may lead to different results.

Each middleware should be responsible for only one functionality to keep the code clean and maintainable.

Middleware should follow consistent interfaces and specifications for easy composition and reuse.

Middleware should perform proper validation and filtering of requests and responses to avoid security holes and data errors. Middleware is a very important part of backend development, it can be used to process requests, respond or perform other tasks. A good middleware design can greatly improve the performance and maintainability of the application.

 

8. Routing

In backend development, routing refers to the process of distributing incoming requests to the appropriate handlers.

Routing is usually determined by the requested URL and HTTP request method. The router can decide which handler to pass the request to based on the URL and the request method.

In backend development, routing is often powered by web frameworks. Here are some common web frameworks and their routing implementations:

Express.js: Express.js is a web framework for Node.js that uses middleware to handle routing. A route consists of an HTTP request method and a URL path

Spring MVC: Spring MVC is a web framework for Java that uses annotations to define routes. A route consists of an HTTP request method and a URL path.

In routing, the HTTP request method is used to specify the request type for resources, such as GET, POST, PUT, DELETE, etc. The URL path is used to specify the requested resource path. Routes are usually directly associated with handlers, which are responsible for processing requests and returning responses. Routing is a very important part of backend development, it determines how requests are assigned to handlers. Good routing design can greatly improve the performance and maintainability of the application.

 

9. Form

In backend development, a form refers to a set of data filled out by a user. Forms usually consist of HTML form elements, such as text boxes, drop-down lists, radio boxes, etc. When a user submits a form, the form data is sent to the backend server, and the backend server can use the form data to perform corresponding operations. In backend development, form data is usually sent to the backend server in two formats: GET and POST. The GET method appends the form data to the URL, while the POST method encapsulates the form data in the HTTP request body. Here are some common form processing operations:

Receiving form data: The backend server can receive form data by accessing the HTTP request object. For the GET method, the form data can be obtained from the request URL. For the POST method, the form data can be obtained from the HTTP request body.

Validate form data: The backend server should validate the validity of the form data. Form data validation usually includes aspects such as data type, format, length, range, etc.

Processing form data: Form data can be used by backend servers to perform actions such as storing the data in a database, sending emails, etc.

Return Response: The backend server should return a corresponding response to the client. Responses typically include aspects such as status codes, messages, redirection URLs, etc. In form processing, you need to pay attention to the following points:

Form data should be validated to avoid security holes and data errors.

Form data should be properly escaped and filtered to avoid cross-site scripting and SQL injection attacks.

Form data should be properly secured during processing to avoid disclosure of sensitive data.

The returned response should include appropriate status codes and messages to provide error handling and debugging information. Forms are a very important part of backend development, it involves data collection, validation, processing and return. Good form design can greatly improve the performance and maintainability of your application.

 

10. Scheduled tasks

Timing tasks for back-end development refer to a program written by programmers to automatically execute certain tasks, which are automatically executed at predetermined time intervals or time points without manual intervention. In back-end development, scheduled tasks are usually used to process some tasks that need to be executed periodically, such as regularly backing up data, sending emails regularly, and updating caches regularly. Timed tasks can improve work efficiency, reduce manual operations, and improve program robustness and reliability. Common timed task frameworks include Quartz, Spring Task, etc.

 

11.SSL

SSL (Secure Sockets Layer) is a secure communication protocol based on the TCP/IP protocol.

It uses digital certificates to authenticate servers and clients, uses encryption to protect the integrity and privacy of transmitted data, and provides a reliable message authentication mechanism, which can effectively prevent data from being tampered with and intercepted.

What encryption methods does SSL use?

The encryption methods used by SSL mainly include RSA, Diffie-Hellman, and AES. Among them, RSA is an asymmetric encryption algorithm that uses public and private keys to encrypt and decrypt data; Diffie-Hellman is a key exchange algorithm that can be used for secure communication between clients and servers; AES is a symmetric encryption algorithm, which can effectively protect the integrity and privacy of transmitted data.

Create value, happy to share!

Guess you like

Origin blog.csdn.net/ly_xiamu/article/details/129324257