SpringBoot入门0x001:idea创建 SpringBoot 项目并运行
文章目录
0x001 创建项目
- 创建一个项目
- 选择 SpringInitializr
- 填写
group、artifact,这两个可以组合成package,一般group是项目域名倒置,artifact是项目名,然后由这两个组合成主包名。 - 添加
web依赖 - 选择项目存储地址
- 勾选自动导入,这个选项可以不选,作用是在
gradle依赖发生变化的时候是否自动导入。 - 等待初次导包结束
- 查看
build.gradle
0x002 创建一个最简单的rest服务并测试
-
添加一个
com.lyxxxx.springbootstudy.controller.HelloController// com.lyxxxx.springbootstudy.controller.HelloController package com.lyxxxx.springbootstudy.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/") public Object hello() { return "hello"; } } - 打开
com.lyxxxx.springbootstudy.SpringbootstudyApplication,并点击运行 - 使用自带服务
IDEA自带REST Client测试(Tools->Http Client->Test RESTFul Service),或者其他任意工具,看到返回hello就成功了
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论