功能:浏览器发送hello请求,服务器接收请求并处理,返回hello word字符串

一、创建一个maven项目

二、在pom.xml文件中添加依赖导入springboot框架运行需要的依赖

     <!-- 继承了一个父项目 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<!-- web模块的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

三、编写一个主程序,自动Springboot

具体启动代码如下:

 /**
* @SpringBootApplication 主程序类的标注
*/
@SpringBootApplication
public class HelloWordMainApplication {
//main方法快捷键是 psvm
public static void main(String[] args) {
//spring boot 应用启动起来,
SpringApplication.run(HelloWordMainApplication.class,args);
}
}

四、编写相关的controller,service

  • 新建一个controller类

  • 具体代码如下

     @Controller
    public class HelloController { @ResponseBody //把接口返回的结果写在浏览器上
    @RequestMapping("/hello") //接收来自浏览器的hello请求
    public String hello(){
    return "Hello Word";
    }
    }

五、启动main程序,在浏览器中打开http://localhost:8080/hello 测试结果,结果返回如下

最新文章

  1. Java 序列化Serializable详解
  2. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Midterm
  3. 【leetcode】Insertion Sort List (middle)
  4. 关闭Eclipse的控制台console自动跳出
  5. [xsd学习]xsd实例
  6. mysql之消息队列
  7. 根据出生日期计算年龄的sql各种数据库写法
  8. Windows7下安装IIS出现“出现错误,并非所有的功能被成功更改
  9. 安装Numpy和matplotlib
  10. IOS 实现QQ好友分组展开关闭功能
  11. Arcgis Runtime sdk for android 授权
  12. Http中的Get/Post方法
  13. Binary Watch
  14. IIS web搭建之虚拟主机
  15. 现在企业开发时,Java所用到的主流框架有哪些?
  16. rest_famework 增删改查初第四阶段(最高级,此阶段是优化第三阶段的代码)的使用
  17. generator详解
  18. &lt;转&gt;jmeter(一)基础介绍
  19. SPL之Iterator(迭代器)接口
  20. void类型详解

热门文章

  1. Python RSA
  2. OpenCV3+VS2015 经常出现debug error abort()has been called问题
  3. 素问 - IC移仓换月
  4. 记录 shell学习过程(8)函数
  5. EF中的上下文(DbContext)简介
  6. k线、指标绘制
  7. [C语言学习笔记四]变量与系统的交互
  8. &lt;meta charset=&quot;utf-8&quot; name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes&quot;/&gt;
  9. 题解【POJ1160】Post Office
  10. 数据库程序接口——JDBC——初篇——目录