第一个SpringBoot程序

1.新建一个Spring Initializr项目

基本配置

image

依赖支持

image
之后就是Maven自动导包,第一次创建会比较慢,以后创建就快了

2.了解项目目录

image

3.运行项目

直接点击运行,项目就可以运行了。不需要过多的配置

image

我们什么都没有配置,默认的界面如下

image

4.新建一个Controller接口

Controller(包括其他的)包要建在与程序主入口的同一个文件夹下
image
编写一个Controller接口

package com.google.hellospringboot.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloControlle {
@RequestMapping("/hello")
public String hello(){
return "hello,world";
}
}

在网页输入http://localhost:8080/hello

image

5.打jar包

image
打开target目录,查看打好的jar包
image

6。暂停IDEA中的服务,在目录下运行该项目

image
在目录空白处按住shift再点击右键,调出Power Shell
之后再运行命令

java -jar .\helloSpringBoot-0.0.1-SNAPSHOT.jar

运行界面如下
image

之后在浏览器中输入http://localhost:8080/hello 访问我们编写的Controller接口
image

posted @   小罗要有出息  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示