创建第一个Springboot项目HelloWorld

作者 : admin 本文共2068个字,预计阅读时间需要6分钟 发布时间: 2024-06-11 共1人阅读

目录

一、准备工作

一、创建springboot项目

三、使用git上传到代码仓库gitee

 四、git使用过程问题总结 


 

一、准备工作

安装jdk:8u201(可以使用高一点的版本)

jdk所有版本下载:Java Archive | Oracle

安装maven:不用安装(idea自带)

安装idea:(2022.2.2-2022.2.5版本,改版本可以下载免费的spring boot helper插件)其他版本 – IntelliJ IDEA

win安装git:Git for Windows 

spring boot helper 插件下载:Spring Boot Helper – IntelliJ IDEs Plugin | Marketplace

插件问题:idea必装的插件 Spring Boot Helper 插件(创建 Spring Boot 项目)-CSDN博客 

插件如果是在idea里下载的话,只有7天免费试用时间。

一、创建springboot项目

打开idea,新建项目,如果左侧没有“spring initializr”,说明spring boot helper插件没有安装成功,如果插件市场没有改插件,说明你的idea版本太老了不支持(试过idea2017版本不支持,推荐2022.2.2-2022.2.5版本)。

创建第一个Springboot项目HelloWorld插图

选择springboot版本,添加spring web插件

创建第一个Springboot项目HelloWorld插图(1)

此处可以更改springboot项目的端口

创建第一个Springboot项目HelloWorld插图(2)

 运行访问

创建第一个Springboot项目HelloWorld插图(3)

创建第一个Springboot项目HelloWorld插图(4)

三、使用git上传到代码仓库gitee

使用git上传代码

打开“git bash here”窗口

创建第一个Springboot项目HelloWorld插图(5)

git生成密钥

#gitee的用户名
git config --global user.name "******"
#gitee的邮箱
git config --global user.email "*******@qq.com"
#生成密钥
ssh-keygen -t rsa "*******@qq.com"

创建第一个Springboot项目HelloWorld插图(6)

在.ssh文件夹下会生成公钥(pub文件)和私钥,私钥是不能让别人知道的,而公钥是需要复制在gitee平台

创建第一个Springboot项目HelloWorld插图(7)

gitee添加公钥

创建第一个Springboot项目HelloWorld插图(8)

测试gitee连接,返回success

创建第一个Springboot项目HelloWorld插图(9)

切换到项目根目录(注意需要根目录里面,而不是根目录当前目录

正式上传代码

#切换到项目跟目录下(注意不是根目录当前文件夹)初始化,初始化后会生成一个隐形.git文件夹
git init

#连接仓库
git remote add origin https://gitee.com/*****/*******.git

#上传目录下的所有文件(常用)
git add .  
#添加需要上传的代码(可以是文件,可以是文件夹)
git add 单个文件或文件夹   (git reset HEAD **** 撤回git add添加过的文件)

#查看提交状态,add后的文件可以使用这条命令查看是否加入到缓存
git status 
 
#上传注释,必须要有
git commit -m "change_file_***"  
 
#正式上传,此步骤会让你登录gitee账户
git push -u origin master

git init初始化,初始化完成后文件夹下生成.git文件夹(是个隐藏文件夹,需要设置下文件夹才能看到)

创建第一个Springboot项目HelloWorld插图(10) 

注意.idea、target等文件不会上传,不用认为是上传没完整 ,是正常现象

创建第一个Springboot项目HelloWorld插图(11)

上传成功

创建第一个Springboot项目HelloWorld插图(12)

 四、git使用过程问题总结 

报错1hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
#远程仓库不为空,仓库创建时自动生成.gitignore文件,本地仓库中并没有这两个文件。需要先pull下来,在push上去
git pull origin master
git pull origin master --allow-unrelated-histories(上述命令无效使用这个)
https://blog.csdn.net/tjh1998/article/details/127325330

报错2 git bash commit 提交 On branch master Changes not staged for commit:
commit命令报错,原因是代码有更新未跟踪,-a可忽略
使用git commit -am “***”解决
https://blog.csdn.net/qq_34739815/article/details/106592858

报错3可撤回git add 添加的文件,使用git status 查看是否已撤回
git reset HEAD ***

报错4 上传的项目文件是不完整的,没有大部分核心文件,但是新建的123.txt文件夹就可以git add成功,这个连git add都失败,git status 查不到add添加的项目文件夹
是正常现象,无须处理,项目克隆到本地时,部署时会重新安装各种包

参考:

搭建SpringBoot项目三种方式(超详细版)_创建springboot项目-CSDN博客

Windows安装Git图文教程_git安装教程 windows-CSDN博客

本站无任何商业行为
个人在线分享 » 创建第一个Springboot项目HelloWorld
E-->