SpringBoot入门一:HelloWorld

文章目录

利用Idea构建SpringBoot项目

系统环境

  • 编辑器:Idea2018.1
  • 操作系统:win7
  • maven:1.8.0_171

步骤

  1. 打开Idea:File->New->Project->Spring Initializr,直接点击下一步SpringBoot启动0SpringBoot启动1
  2. 跳出的界面设置Group、Artifact、Version、Type(这里我使用的默认的Maven Project),下一步SpringBoot启动2
  3. 跳出的选项Dependencies中选择Web,并在右侧勾选Web,点击下一步SpringBoot启动3
  4. 确认名称和路径,直接点击FinishSpringBoot启动4
  5. 启动后目录如下:SpringBoot启动5

这样我们就算成功创建了SpringBoot项目,但是想要看到项目跑起来的效果,可以再DemoApplication.java所在目录下新建controller/DemoController.java测试

package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 第一个SpringBoot接口测试
 */
@RestController
public class DemoController {
	/**
     * 输出HelloWorld!
     * @return String "HelloWorld!"
     */
    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    public String helloWorld(){
        return "HelloWorld!";
    }
}

运行项目,当看到

Completed initialization in xxx ms

时,打开Tool->Http Client->Test RESTful Web ServiceSpringBoot运行
请求GET:localhost:8080/demo
查看Response返回了我们需要的结果:
SpringBoot运行2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值