开发日记2-创建http文件测试http接口

创建接口

创建com.wz.nls.business.controller

在controller包下创建TestController.java

java 复制代码
package com.wz.nls.business.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @GetMapping("/hello")
    private String hello() {
        return "hello world";
    }
}

创建http测试

在根目录下创建http文件夹,创建test.http文件

键入gtr,自动补全

java 复制代码
GET http://localhost:8080/hello
Accept: application/json

###

启动主程序,测试

GET http://localhost:8080/hello

HTTP/1.1 200

Content-Type: application/json

Content-Length: 11

Date: Mon, 29 Dec 2025 12:22:13 GMT

hello world

响应文件已保存。

> 2025-12-29T202213.200.json

Response code: 200; Time: 72ms (72 ms); Content length: 11 bytes (11 B)

修改运行参数

运行参数在/data/wz/JavaProject/im-nls/business/src/main/resources/application.properties中

java 复制代码
spring.application.name=business
server.servlet.context-path=/nls
server.port=18000

修改/data/wz/JavaProject/im-nls/business/src/main/java/com/wz/nls/business/BusinessApplication.java

增加getEnvironment,能够environment.getProperty获取运行参数

ctrl+alt+v自动生成变量,并引入log,打印log到控制台

java 复制代码
package com.wz.nls.business;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.ConfigurableEnvironment;
@Slf4j
@SpringBootApplication
public class BusinessApplication {

    public static void main(String[] args) {
        ConfigurableEnvironment environment = SpringApplication.run(BusinessApplication.class, args).getEnvironment();
        log.info("启动成功!");
        log.info("测试地址:http://localhost:{}{}/hello",
                environment.getProperty("server.port"),
                environment.getProperty("server.servlet.context-path"));
    }

}

同时修改http测试

java 复制代码
GET http://localhost:18000/nls/hello
Accept: application/json
相关推荐
VOOHU-沃虎30 分钟前
沃虎——网络变压器与RJ45集成连接器选型实战:从百兆到10G、从非PoE到4PPoE
网络
2301_773643621 小时前
华为云存储实验
网络·mysql·华为云
ylscode1 小时前
Windows 内核惊现高危提权漏洞 CVE-2026-40369:沙箱隔离失效,SYSTEM 权限唾手可得
网络·安全·安全威胁分析
jieyu11191 小时前
Wireshark使用指南【超全面】
网络·wireshark
weixin_520649872 小时前
通信【报文】
网络
志栋智能2 小时前
小步快跑:从单一场景开启超自动化巡检之旅
运维·网络·人工智能·自动化
XINERTEL2 小时前
视频卡顿花屏?专业视频质量评估测试让画质从“凭感觉”到“数据说话”
网络·测试工具·音视频·丢包
AugustRed2 小时前
Linux 运维常用命令大全(超全速查表)
运维·网络·php
正在走向自律2 小时前
远程控制软件安全对比2026:ToDesk vs 向日葵 vs TeamViewer,你的电脑钥匙交给谁更放心
网络·远程办公·远程服务
胡楚昊3 小时前
Vulnhub靶场 Tr0ll打靶(上)
网络