版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/slwhy/article/details/89439562
任务要求
- 使用idea创建一个springboot项目
- 在浏览器上显示hello world
- 使用maven将项目打包成jar文件
项目进程
创建项目
- 打开idea,点击 file–>new–>project
- 选择Spring Initializr,然后点击next
- 定义项目组
- 添加web依赖
- 定义项目名称以及存放位置(至此一个项目就创建完毕)
- 编写一个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. 打开浏览器输入
用maven将项目打包成jar包
打包完成后,你会发现你的target目录下多了一个文件,其中有一个以jar结尾的文件,就是打包好的项目文件
而后在当前目录下,输入一条命令即可执行jar文件
java -jar 文件名称
总结
- 如何利用idea创建一个springboot项目
- 如何利用springboot在浏览器输出一个helloworld
- 如何利用maven将springboot项目打包成一个jar包,并执行