Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Rest调用中将具有不相关细节的ID或对象作为RequestBody传递?_Rest_Spring Boot_Oop_Spring Restcontroller_Spring Rest - Fatal编程技术网

在Rest调用中将具有不相关细节的ID或对象作为RequestBody传递?

在Rest调用中将具有不相关细节的ID或对象作为RequestBody传递?,rest,spring-boot,oop,spring-restcontroller,spring-rest,Rest,Spring Boot,Oop,Spring Restcontroller,Spring Rest,方法1: @PostMapping("/api/{id}") String getSomeObj(int id){ //make another rest call with id and get CustomObj // then do some logic and return something //Here response time will be more as it has again another rest calls } 方法2: @PostMap

方法1:

@PostMapping("/api/{id}")
String getSomeObj(int id){
    //make another rest call with id and get CustomObj
    // then do some logic and return something
    //Here response time will be more as it has again another rest calls

}
方法2:

@PostMapping("/api/{id}")
String getSomeObj(@PathParam("id") int id, @RequestBody CustomObj obj){
    //directly do logic with the provided obj and return something
    //Here Response time would be less as we are directly getting the actual Object from Request Body
    //BUT is this a good practise to pass an object in which we need only few details?
}
Q1)我要问的是是否只传递id还是对象?如果id被传递,则必须进行另一个不必要的Rest调用。如果对象被传递,我们可以避免进行另一个rest调用,但问题是:这个自定义对象可能也包含一些不相关的细节。。那么,这是正确的吗

Q2)如果使用id传递,则与仅传递的对象相比,响应时间会更长。。因此,我不明白应该采取哪种方法

A1)这一切都取决于你,没有“一个正确”的方法。我会说,如果它是一个小物体,通过这个物体,反应很快。如果它是一个大对象,则传递id。如何定义大对象和小对象?若对象中有哈希映射或列表,那个就是一个大对象。也可以忽略内部的序列化;检查

A2)出示身份证,享受休息服务。毕竟休息很快。不要担心电话的速度。如果你的后端功能是快速的,如果你把一个“加载”的gif到前端;用户将等待响应