开发日记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
相关推荐
liulovesong1 天前
2024/06/21/第三天
http·echarts
chian-ocean1 天前
深入 CANN:使用 `tbe-op` 构建自定义高性能算子
网络
中议视控1 天前
可编程网络中央控制系统主机通过红外发射棒控制空调电视等红外设备
网络·物联网·5g
数据安全科普王1 天前
打破中心枷锁:P2P网络如何用“去中心化”重构互联网通信
网络·去中心化·p2p
爱吃烤鸡翅的酸菜鱼1 天前
CANN ops-nn激活函数与池化算子深度解析
网络·开源·aigc
saber_andlibert1 天前
TCMalloc底层实现
java·前端·网络
飞凌嵌入式1 天前
用「EN 18031认证」通关欧盟,这张 “网络安全护照” 已就位
网络·安全·能源
Trouvaille ~1 天前
TCP Socket编程实战(三):线程池优化与TCP编程最佳实践
linux·运维·服务器·网络·c++·网络协议·tcp/ip
JoySSLLian1 天前
手把手教你安装免费SSL证书(附宝塔/Nginx/Apache配置教程)
网络·人工智能·网络协议·tcp/ip·nginx·apache·ssl
Zach_yuan1 天前
自定义协议:实现网络计算器
linux·服务器·开发语言·网络