gpt4 book ai didi

java - 离线同步文件: Upload ArrayList or Upload in a for loop

转载 作者:行者123 更新时间:2023-12-02 10:13:00 27 4
gpt4 key购买 nike

我基本上是一名 Java 开发人员,仅了解有关 Android 开发的基本信息。我开发了一个 Web 端点,它接受文件和一些其他参数。 java代码是

@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile file,
@RequestParam("hdId") Long hdId, @RequestParam("toRegId") String toRegId,
@RequestParam(value = "remark", required = false) String remark,
@RequestParam(value="latitude")String latitude,
@RequestParam(value="longitude")String longitude) {
//.... Method Code
}

我的 Android 开发人员表示,在异步后台线程上上传 10 个文件需要 10 分钟,因为它必须点击 URL 10 次。她建议我更改 API 以接受 ArrayList。即将界面更改为

@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile[] files,
@RequestParam("hdId") Long[] hdIds, @RequestParam("toRegId") String[] toRegIds,
@RequestParam(value = "remark", required = false) String[] remarks,
@RequestParam(value="latitude")String[] latitudes,
@RequestParam(value="longitude")String[] longitudes) {
for (int idx = 0; idx < hdIds.length; idx++)
{
//... Same code as in current method
officerSvc.save(.....)
}
}

注意复数形式和[]

我的基本问题是:是否建议更改 api 以接受 ArrayList/Array 而不是单个实例,以便以其优点提高上传性能?事实还是虚构?

最佳答案

是的,这将节省在客户端和服务器之间创建连接的时间。不过也不是很多,大概1-2秒吧。

关于java - 离线同步文件: Upload ArrayList or Upload in a for loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54860765/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com