完成一个基本spring-boot项目的框架搭建,本篇最基本的搭建,即在页面显示hello word
使用工具:idea开发
目标:搭建一个spring-boot的web项目,
点击菜单栏 file---->new---->project 出现下图页面
![a2709f6d688250caef2a6246a2c80369.png](https://img-blog.csdnimg.cn/img_convert/a2709f6d688250caef2a6246a2c80369.png)
Spring Boot 2.2.0版的需要JDK8
![bc20cde2efdcfa055a794936c56df661.png](https://img-blog.csdnimg.cn/img_convert/bc20cde2efdcfa055a794936c56df661.png)
![61637dbf8294b0852778c9abec837b56.png](https://img-blog.csdnimg.cn/img_convert/61637dbf8294b0852778c9abec837b56.png)
点击next
![c5f70aeccbdc3eaeb644561bfa8b263e.png](https://img-blog.csdnimg.cn/img_convert/c5f70aeccbdc3eaeb644561bfa8b263e.png)
选择web勾选web点击next,这里我们以最简单的搭建,左边栏sql选择也可以集成mybatis进来,点击“next”,到最后一个页面如图:
![adb189b96cd89883a01f01e6f46d5282.png](https://img-blog.csdnimg.cn/img_convert/adb189b96cd89883a01f01e6f46d5282.png)
![0c78fe39a40a9a80229668d768304e41.png](https://img-blog.csdnimg.cn/img_convert/0c78fe39a40a9a80229668d768304e41.png)
然后点击项目名称,和前面的文件名相同,自动同步的前面的文件名
![1a7eaa13d42754ee8a25783deb51d81a.png](https://img-blog.csdnimg.cn/img_convert/1a7eaa13d42754ee8a25783deb51d81a.png)
点击“finish”,项目创建成功。目录结构如图:
![31eccd74c6f3a8ac2b2be9f037f88ce4.png](https://img-blog.csdnimg.cn/img_convert/31eccd74c6f3a8ac2b2be9f037f88ce4.png)
然后新建一个类
![a9d6f769afcc1edacc5f33a8a5a377c8.png](https://img-blog.csdnimg.cn/img_convert/a9d6f769afcc1edacc5f33a8a5a377c8.png)
类的代码是
![178c5bb13347cf8b8f1f2a37ca8c7e85.png](https://img-blog.csdnimg.cn/img_convert/178c5bb13347cf8b8f1f2a37ca8c7e85.png)
@Controllerpublic class HelloController { //RequestMapping 表示接受浏览器hellO的请求 @ResponseBody @RequestMapping("/hello") public String hello(){ //将在浏览器返回一个“hello world” 展现出来 return "hello world"; }}
然后启动类
![65af7c582b889d424a928df85d005668.png](https://img-blog.csdnimg.cn/img_convert/65af7c582b889d424a928df85d005668.png)
@SpringBootApplicationpublic class MybatisappApplication { public static void main(String[] args) { SpringApplication.run(MybatisappApplication.class, args); }}
启动成功
![5443c8030efa90e233be04116f574991.png](https://img-blog.csdnimg.cn/img_convert/5443c8030efa90e233be04116f574991.png)
然后在浏览器输入:http://localhost:8080/hello
![ebe6fd6b2d9f28fd372b19081145a992.png](https://img-blog.csdnimg.cn/img_convert/ebe6fd6b2d9f28fd372b19081145a992.png)
访问成功