在我的请求方法
中添加参数后,在Retrofit错误中收到400 Bad Request错误@GET("/api/add/remark")
void addRemark(@Header("Cookies") HttpCookie cookie, @Query("tenantId") long tenantId, @Query("userId") long userId, @Query("comment") String commentJson, @Query("file") MultipartEntityBuilder multipartEntity, Callback<CreationResponse> callback);
这是我服务器收到它的方式
@RequestMapping("add/remark")
@Secured({"ROLE_ADMIN","ROLE_SITE_USER","ROLE_FIELDUSER"})
@JsonInclude(Include.NON_NULL)
public @ResponseBody
CreationResponse addRemarkController1(@RequestParam String comment,@RequestParam Integer userId,@RequestParam long tenantId,@RequestParam("file") MultipartFile file,HttpServletRequest request) {}
如果双方都省略了multipart参数,则可以发送备注而不会失败。
这是我的MultipartEntity添加图片
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
entity.addBinaryBody("file", input, ContentType.create("image/jpeg"),photosPath.getName());