I. Development environment and tools

A good tool works twice with half the effort.

1.1 Development Environment

Although the Java JDK version has now reached 16, JDK8 is still the most used, most stable and long-term maintenance version, and it is recommended to use JDK8.

JDK8 download link www.oracle.com/java/techno… (You need an Oracle account to download it.)

Java JDK environment variable configuration recommendations on the web search, also very simple.

1.2 Development Tools

IDEA is strongly recommended as it is much easier to use than Eclipse. If it comes from Eclipse, you may not get used to it at first, but after a few days you will like it.

Download IntelliJ IDEA at www.jetbrains.com/idea/

1.3 Interface Debugging Tool

Interface debugging tools use Postman, also needless to say.

Postman download link www.postman.com/downloads/

2. Create a project

Create a SpringBoot project with IDEA

Open IDEA and click Create new project

To create a Spring project, if the default URL is too slow, you can use aliyun’sstart.aliyun.com

Fill in engineering Information

Artifact: Type: Maven And then Java version 8,

In this step, focus on the version of SpringBoot and click Next

Project creation succeeded

3. Modify the configuration and run the project

Delete the test directory from SRC. This directory is for testing.

3.1 the pom. XML

XML file in the project root directory, Maven project packages depend on the management file, the project needs Jar packages directly configured here.

Pom.xml is modified as follows


      
<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>
    <groupId>com.llh</groupId>
    <artifactId>spring-boot-demo1</artifactId>
    <version>1.0.0</version>
    <name>spring-boot-demo1</name>
    <description>I met springboot</description>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.3.7. RELEASE</spring-boot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

    </dependencies>

</project>

Copy the code

3.2 Project configuration file application.properties

Nonsense: SpringBoot is good to use “convention than configuration”, but still need to configure, in fact, is in accordance with its provisions to configure, we have a convention

Application. Properties (8080 by default

spring.application.name=spring-boot-demo1
server.port=8080
Copy the code

3.3 Running projects

4. Write interfaces

4.1 get request

There are two methods for sending parameters in a GET request

    / get request http://localhost:8080/test1/admin * * * * * / parameter interpolation
    @GetMapping("/test1/{name}")
    public String test1(@PathVariable("name") String name) {
        return name;
    }

    / * * * a get request to http://localhost:8080/test2? Name =admin * Traditional method with parameters */
    @GetMapping("/test2")
    public String test2(@RequestParam("name") String name) {
        return name;
    }
Copy the code

4.2 a post request

The POST request writes a class object directly as the receiving object

    /** * Post request localhost:8080/test3 * The parameter is in Json format * {* "username":"admin", * "password":"123456" *} */
    @PostMapping("/test3")
    public String test3(@RequestBody UserInfo userInfo) {
        return userInfo.toString();
    }
Copy the code

Isn’t that easy

HelloController class

package com.llh.springbootdemo1.controller;

import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {

    / get request http://localhost:8080/test0 * * * * * / without parameters
    @GetMapping("/test0")
    public String test0(a) {
        return "hello world";
    }

    / get request http://localhost:8080/test1/admin * * * * * / parameter interpolation
    @GetMapping("/test1/{name}")
    public String test1(@PathVariable("name") String name) {
        return name;
    }

    / * * * a get request to http://localhost:8080/test2? Name =admin * Traditional method with parameters */
    @GetMapping("/test2")
    public String test2(@RequestParam("name") String name) {
        return name;
    }

    /** * Post request localhost:8080/test3 * The parameter is in Json format * {* "username":"admin", * "password":"123456" *} */
    @PostMapping("/test3")
    public String test3(@RequestBody UserInfo userInfo) {
        returnuserInfo.toString(); }}Copy the code

The UserInfo class

package com.llh.springbootdemo1.controller;

public class UserInfo {
    private String username;
    private String password;

    public String getUsername(a) {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword(a) {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString(a) {
        return "UserInfo{" +
                "username='" + username + '\' ' +
                ", password='" + password + '\' ' +
                '} '; }}Copy the code

4.3 Testing Interfaces

Get requests can be typed directly into the browser

The Postman tool is used for post requests. Note that the interface mode is changed to POST and the input parameters are changed to JOSN format

Five, the conclusion

I haven’t written a blog for three or four years. First, I don’t have time. Second, I’m lazy. It’s time to start a new blog. It’s a way to share your skills and improve yourself.

This is the first blog, SpringBoot is the most simple entry blog, then we will enter The SpringBoot persistence framework Mybatis, Mybatis-Plus, relational database Mysql, memory database Redis, JWT and other mono application technology. Then we will learn about spring-Cloud-Alibaba microservices, Including service registry and configuration center Nacos, service call OpenFeign, Gateway Gateway, stream limiting degradation Sentinel, message queue RocketMQ, distributed transaction Seata, distributed lock Redisson, distributed task scheduling xxL-job and other technologies. I will also share Nginx, Tomcat, Docker, Linux and more.

In addition, I will write some articles about front-end technologies such as Vue, ElementUI, AntdDesign, and Flutter. I hope this article will focus on application first and then talk about some theoretical knowledge.

Because my personal belief is that if you’re an application developer, make sure it’s full stack. My personal plan is also like this, is to be a full stack engineer. It was hard to do full stack before, but with SpringBoot, with Vue, with Flutter, all these nice framework tools. It is possible to be a full stack engineer.

The final system is

Back end: Spring-boot Spring-cloud-Alibaba system Web end: Vue system APP end: Flutter system

I hope I can stick to this road of blogging!

Synchronize wechat official account: Little Tiger’s technology blog