SpringBoot2.xHelloWorld

使用IDEA2018创建第一个SpringBoot项目.
第一个:
在这里插入图片描述
第二个:注意Artifact不能出现大写英文字母,这里使用“-”作为多个单词的分隔。
在这里插入图片描述
第三个:
在这里插入图片描述
第四个:
在这里插入图片描述
点击finish,项目创建完毕。
项目结构如下:
在这里插入图片描述
编写第一个Controller:
在这里插入图片描述

package com.linglib.myproject.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    
    
    @RequestMapping("/test")
    public String test(){
    
    
        return "test!";
    }
}

启动项目,正常会启动成功。我这里报错,原因是8080端口被占用:
在这里插入图片描述
在properties文件设置端口使用8081
在这里插入图片描述
重新启动项目,在浏览器输入http://localhost:8081/test
在这里插入图片描述

おすすめ

転載: blog.csdn.net/JWbonze/article/details/108779949