我有一个使用 JERSEY 的工作 REST 设置。对于一组不同的实体,我需要几乎相同的功能。我需要做什么来克隆这个当前的功能?
@Path("/will")
public class FileResource {
private final BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
private final BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
/* step 1. get a unique url */
@GET
@Path("/url")
public Response getCallbackUrl() {
/* this is /_ah/upload and it redirects to its given path */
String url = blobstoreService.createUploadUrl("/rest/will");
return Response.ok(new FileUrl(url), MediaType.APPLICATION_JSON).build();
}
/* step 2. post a file */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void post(@Context HttpServletRequest req, @Context HttpServletResponse res) throws IOException, URISyntaxException {
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("files[]");
res.sendRedirect("/rest/will/" + blobKey.getKeyString() + "/meta");
}
....
我可以简单地复制这个类并将意志改为其他东西吗?