springboot实战一:helloworld

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/slwhy/article/details/89439562

任务要求

  • 使用idea创建一个springboot项目
  • 在浏览器上显示hello world
  • 使用maven将项目打包成jar文件

项目进程

创建项目

  1. 打开idea,点击 file–>new–>project
    在这里插入图片描述
  2. 选择Spring Initializr,然后点击next
    在这里插入图片描述
  3. 定义项目组
    在这里插入图片描述
  4. 添加web依赖
    在这里插入图片描述
  5. 定义项目名称以及存放位置(至此一个项目就创建完毕)
    在这里插入图片描述
  6. 编写一个controller
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Hellocontroller {
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String sayHello(){
        return "hello world";
    }
}

目录结构如下
在这里插入图片描述
7. 运行程序(在Application文件下单击右键)
在这里插入图片描述
8. 打开浏览器输入

http://localhost:8080/hello

在这里插入图片描述

用maven将项目打包成jar包

在这里插入图片描述
打包完成后,你会发现你的target目录下多了一个文件,其中有一个以jar结尾的文件,就是打包好的项目文件
在这里插入图片描述
而后在当前目录下,输入一条命令即可执行jar文件

java -jar 文件名称

在这里插入图片描述

总结

  • 如何利用idea创建一个springboot项目
  • 如何利用springboot在浏览器输出一个helloworld
  • 如何利用maven将springboot项目打包成一个jar包,并执行

猜你喜欢

转载自blog.csdn.net/slwhy/article/details/89439562
今日推荐