新建一个springboot工程。使用以下几步即可。

1.1. 1、搭建工程。

1.1.1. 使用start.spring搭建工程

访问http://start.spring.io/。如下图所示:
start.spring.io图片

选择好相关的参数,特别是填写好Group(一般是公司网站域名反过来写)和Artifact(项目名)。可以把压缩包下载到本地。

1.1.2. 使用idea搭建工程

如果是使用idea搭建工程,实际上idea后台也是去访问http://start.spring.io/搭建工程。如下图:
idea图片
配送好相关的参数即可。

1.2. 2、工程结构。

搭建好之后。如下图:
工程结构图

  • 源文件目录 src/main/java
  • 测试文件目录 src/test/java
  • 配置文件/静态文件目录 src/main/resources

    1.3. 3、运行工程。

    下面的UserProviderApplication.java是工程的入口,运行这个main方法就可以运行工程了。
    工程入口图

    1.3.1. 4、写一个API。

    添加web依赖。

    我创建工程的时候,选择了添加web依赖,如果没有就在pom.xml添加web依赖。如下:

    <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    添加一个UserController

    ```java @RestController @RequestMapping("/users") public class UserController {

    @RequestMapping("/hello") public String findById() {

     return "hello from user_provider";
    

    }

} `` 启动之后访问http://localhost:8080/users/hello`就可以看到返回了。

results matching ""

    No results matching ""