我基本上是一名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分钟,因为它必须点击10次URL。她建议我将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秒。

10-07 19:07
查看更多