Location>code7788 >text

July Programming Tips

Popularity:752 ℃/2024-08-10 00:59:12

July is very busy, want to systematically write an article, several times do not know how to start, and then think it would be better to go with the flow, write a little bit of their own learning experience.

This article, talk about the author's programming experience in July , I hope to help you.

1 IntelliJ IDEA Community Edition

If you want to do a good job, you have to make good use of your tools.

The author's Mac computer installed IntelliJ IDEA Ultimate Edition 2018, an abnormal shutdown, Ultimate Edition can no longer start, do not want to use the cracked version, so downloaded the IntelliJ IDEA Community Edition.

Experiencing it, I was pleasantly surprised with a very fast startup and a very clean interface.

During the development process, there are basically no lagging scenarios, and the free plugins in the market can basically satisfy one's needs .

2 Hutool First Experience

Hutool is a very hot Java tools library in recent years , I have not been used, this month I had the opportunity to try some.

This hands-on exercise uses two features of Hutool:HTTP Client cap (a poem)JSON Parsing Tools

1、HTTP Client

We can rely on them as needed, for example, if we only need the HTTP client tool, we only need to rely on the following components:

<dependency>
    <groupId></groupId>
    <artifactId>hutool-http</artifactId>
    <version>5.8.25</version>
</dependency>

The following figure shows the flow of executing an HTTP GET:

If we want to switch to a POST request, it's a simple change:

I have also packaged HTTP utility classes, the general approach is similar:

Above, the author defines an HTTP tool class and defines several static public methods in the class for use. This tool class is very easy to implement, but still seems very rough.

And the Hutool HTTP utility is used in the following waychain call The so-called chained call is a continuous method call by setting the return value of a method so that the return value becomes the object itself.

Hutool provides GenericBuilder class, which can realize chain call, the specific implementation code is as follows:

The use of chained calls improves the readability and composability of the code, making it more concise, flexible and easy to maintain, a programming technique worth learning.

2, JSON parsing tools

I used to use more JSON parsing tool is Ali's FastJSON , the project uses Hutool JSON, so also try to use a little.

The business interface to which the author interfaces returns results in the format shown above, defining a response class:

The results are then directly converted into relevant data entities:

For example, when parsing product information, the following method is called:

From the point of view of using experience, the difference between Hutool JSON and FastJSON is not big, the API is very similar, and it is still very smooth to use.

3 Integrating the e-commerce supply chain

An e-commerce company has a self-developed mall APP, the goods come from A supply chain, the company leader talked about another supply chain B, want to let the technical team to access, so as to enrich the diversity of goods in the mall.

However, two months had passed and the technical team was making very slow progress. After the task was given to the author, it took him 1 month to initially integrate the supply chain together.

The above figure is the original process of the user to place an order, when the payment is successful, the payment service will supply chain A's submit order service to create the supply chain order and write back to the database.

If more than one supply chain is introduced, it will become complicated for each business system to interact with more than one supply chain system, so from the point of view of service invocation, the author has introduced astand alone(used form a nominal expression)Supply Chain Services , the figure below provides an overview of the design of supply chain services.

Different supply chain companies provide different API interfaces, and if each call to the supply chain interface is judged by if else, the code becomes extremely difficult to maintain.

Therefore, I designed an adapter layer, similar to the adapter layer of the author's open source SMS service.

短信服务适配器层

However, compared with the SPI mechanism of SMS service, considering the R&D cost, as well as the convenience for other R&D students to maintain, the author has simplified the supply chain adapter very much.

供应链适配器层

The Supply Chain Adapter core interface is shown below:

When calling the supply chain interface, you create the adapter through the adapter constructor and then just call the adapter's methods.

After about three weeks of research and development, I basically integrated Supply Chain B. At the same time, the supply chain service-oriented to improve the maintainability of the system.

4 Write to the end

The task of integrating the supply chain, although basically completed, but the author does not have a lot of sense of accomplishment, on the one hand, because there have been countless large and small reconfiguration, the senses are a little numb.

On the other hand, many managers have always thought that technology is easy, but the truth is that there are some things that they really can't handle without investment and attention to technology.

Technology has always been the same: overvalued for a short time and undervalued for a long time.


Hutool Address:/

IDEA Community Edition:/idea/download/