Spring Boot REST API 端点映射最佳实践 [英] Spring Boot REST API Endpoint Mapping best practice

查看:72
本文介绍了Spring Boot REST API 端点映射最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的端点 URL 映射和 HTTP 方法,例如(POST、DELETE、GET、PUT)

I am using below endPoint URL Mapping with HTTP Methods like ( POST, DELETE, GET, PUT)

POST 用于创建新交易 -

POST for Create a new Trade -

@PostMapping("/trade")

DELETE 用于删除具有特定 ID 的交易 -

DELETE for Delete a Trade with specific id -

@DeleteMapping("/trade/{id}")

GET 用于获取特定交易的详细信息 -

GET for Get details of specific Trade -

@GetMapping("/trade/{id}")

PUT 更新交易详情 -

PUT for Update Trade details -

@PutMapping(/trade/{id}")

GET for Retrieve all Trade list of the collection -

GET for Retrieve all Trade list of the collection -

@GetMapping("/trades")

Spring 目前支持五种类型的内置注解,用于处理不同类型的传入 HTTP 请求方法,即 GET、POST、PUT、DELETE 和 PATCH.这些注释是:

Spring currently supports five types of inbuilt annotations for handling different types of incoming HTTP request methods which are GET, POST, PUT, DELETE and PATCH. These annotations are:

@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping

从命名约定可以看出,每个注解都是为了处理各自传入的请求方法类型,即@GetMapping用于处理GET类型的请求方法,@PostMapping用于处理POST类型的请求方法,等

From the naming convention, we can see that each annotation is meant to handle the respective incoming request method types, i.e. @GetMapping is used to handle GET type of request method, @PostMapping is used to handle POST type of request method, etc.

如果我在这里遗漏了什么请提出建议

if I am missing anything here Please suggest

推荐答案

Add API version like

Add API version like

@RestController
@RequestMapping("/API/V1")
public class TestController {

@RequestMapping("/greeting")
    public String greeting( {
        return "welcome";
    }
}

这篇关于Spring Boot REST API 端点映射最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆