springboot 框架 - helloword
2024-09-21 12:54:52
功能:浏览器发送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 测试结果,结果返回如下
最新文章
- Java 序列化Serializable详解
- 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Midterm
- 【leetcode】Insertion Sort List (middle)
- 关闭Eclipse的控制台console自动跳出
- [xsd学习]xsd实例
- mysql之消息队列
- 根据出生日期计算年龄的sql各种数据库写法
- Windows7下安装IIS出现“出现错误,并非所有的功能被成功更改
- 安装Numpy和matplotlib
- IOS 实现QQ好友分组展开关闭功能
- Arcgis Runtime sdk for android 授权
- Http中的Get/Post方法
- Binary Watch
- IIS web搭建之虚拟主机
- 现在企业开发时,Java所用到的主流框架有哪些?
- rest_famework 增删改查初第四阶段(最高级,此阶段是优化第三阶段的代码)的使用
- generator详解
- <;转>;jmeter(一)基础介绍
- SPL之Iterator(迭代器)接口
- void类型详解
热门文章
- Python RSA
- OpenCV3+VS2015 经常出现debug error abort()has been called问题
- 素问 - IC移仓换月
- 记录 shell学习过程(8)函数
- EF中的上下文(DbContext)简介
- k线、指标绘制
- [C语言学习笔记四]变量与系统的交互
- <;meta charset=";utf-8"; name=";viewport"; content=";width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes";/>;
- 题解【POJ1160】Post Office
- 数据库程序接口——JDBC——初篇——目录