从零开始搭建一个SpringBoot项目的详细图解

从零开始搭建一个SpringBoot项目的详细图解

开发工具:idea,maven

1.创建一个maven项目从零开始搭建一个SpringBoot项目的详细图解_第1张图片 从零开始搭建一个SpringBoot项目的详细图解_第2张图片

从零开始搭建一个SpringBoot项目的详细图解_第3张图片
ok,我们项目创建好了之后就是下面这个样子
从零开始搭建一个SpringBoot项目的详细图解_第4张图片

2.pom.xml文件里面配置需要引入的jar包

从零开始搭建一个SpringBoot项目的详细图解_第5张图片

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE </version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

ok,导入之后你会发现SpringBoot的一些jar包已经导入进来了
从零开始搭建一个SpringBoot项目的详细图解_第6张图片

3.新建一个类,用来编写SpringBoot的启动类

从零开始搭建一个SpringBoot项目的详细图解_第7张图片
从零开始搭建一个SpringBoot项目的详细图解_第8张图片
ok,启动类写好之后我们来启动一下,看看SpringBoot是否已经可以启动类,如果启动之后出现下面的界面,说明已经启动成功了
从零开始搭建一个SpringBoot项目的详细图解_第9张图片

4.创建一个Controller,用来模拟运行一下SpringBoot项目

从零开始搭建一个SpringBoot项目的详细图解_第10张图片

package api.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *如果你是返回json数据的话,就可以使用@RestController注解,因为这个注解包含了@Controller和@ResponseBody注解
 * 如果你需要返回视图的话,就只能使用@Controller注解,我这里为了能够使大家知道@ResponseBody注解怎么使用,我就不使用@RestController注解了
 */

//@RestController
@Controller
public class HellowWorldController {
    @ResponseBody
    @RequestMapping("/hellowWorld")
    public String HellowWorld(){
        return "Hellow,World;Hellow,Ximi";
    }
}

ok,我们来启动一下项目,然后打开浏览器,输入127.0.0.1:8080/hellowWorld
从零开始搭建一个SpringBoot项目的详细图解_第11张图片
ok,成功的显示我们在controller里面定义的内容

ps:我写得可能有点啰嗦,第一次写博客,如果有什么写得不好的地方还请大神们多多指教

你可能感兴趣的:(从零开始搭建一个SpringBoot项目的详细图解)