一、准备工作
目前企业主流是前后端分离开发,所以我们要借助一款网页调试与发送网页HTTP请求的软件Apifox 下载安装后 打开Apifox点击加号新建一个快捷请求。
二、idea开发步骤
新建一个spring boot模块 新建一个类 Requestcoller
代码如下:
package com.test.huang.huang1;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 定义一个请求处理类
@RestController
public class Requestcoller {
//定义请求路径
@RequestMapping("/hello")
public String hello(String name,Integer age) {
System.out.printf("姓名:%s%n年龄 %d%n",name,age);
return "ok";
}
}
打开Apifox 输入网址 点击发送返回ok
控制台输出数据