本文整理汇总了Java中org.springframework.web.bind.annotation.RequestPart类的典型用法代码示例。如果您正苦于以下问题:Java RequestPart类的具体用法?Java RequestPart怎么用?Java RequestPart使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestPart类属于org.springframework.web.bind.annotation包,在下文中一共展示了RequestPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userAvatarUpdate
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@RequestMapping(value = "/user/avatar/update", method = RequestMethod.POST, consumes = { "multipart/form-data" })
public @ResponseBody GenericResponseBody userAvatarUpdate(@RequestPart("avatar_data") AvatarRequest avatarRequest,
@RequestPart("avatar_file") MultipartFile file) {
User authenticatedUser = new AuthenticationHolder().getAuthenticatedUser();
User persistentUser = userService.findByPK(authenticatedUser.getId());
try {
persistentUser.setPicture(Utility.cropImage(file.getBytes(), avatarRequest.getX().intValue(),
avatarRequest.getY().intValue(), avatarRequest.getWidth().intValue(),
avatarRequest.getHeight().intValue(), avatarRequest.getScaleX() == -1 ? true : false,
avatarRequest.getScaleY() == -1 ? true : false, avatarRequest.getRotate()));
} catch (BusinessException | IOException e) {
return new GenericResponseBody(GenericResponseBodyState.ERROR);
}
userService.update(persistentUser);
return new GenericResponseBody(GenericResponseBodyState.SUCCESS);
}
示例2: post
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PostMapping("/")
@ResponseBody
ResponseEntity<StreamingResponseBody> post(@RequestPart final MultipartFile file)
throws Exception {
if (file.isEmpty()) {
throw new ValidationException("file was empty");
}
final HttpHeaders headers = new HttpHeaders();
headers.setContentDispositionFormData("filename", "sample.txt");
final StreamingResponseBody body = out -> out.write(file.getBytes());
return ResponseEntity.ok()
.headers(headers)
.contentType(MediaType.valueOf("application/force-download"))
.body(body);
}
示例3: update
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
/**
* @api {patch} /credentials/:name Update
* @apiParam {String} name Credential name to update
*
* @apiParamExample {multipart} RSA-Multipart-Body:
* the same as create
*
* @apiGroup Credenital
*/
@PatchMapping(path = "/{name}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@WebSecurity(action = Actions.ADMIN_UPDATE)
public Credential update(@PathVariable String name,
@RequestParam(name = "detail") String detailJson,
@RequestPart(name = "android-file", required = false) MultipartFile androidFile,
@RequestPart(name = "p12-files", required = false) MultipartFile[] p12Files,
@RequestPart(name = "pp-files", required = false) MultipartFile[] ppFiles) {
// check name is existed
if (!credentialService.existed(name)) {
throw new IllegalParameterException("Credential name does not existed");
}
CredentialDetail detail = jsonConverter.getGsonForReader().fromJson(detailJson, CredentialDetail.class);
return createOrUpdate(name, detail, androidFile, p12Files, ppFiles);
}
示例4: supportsParameter
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
/**
* Supports the following:
* <ul>
* <li>annotated with {@code @RequestPart}
* <li>of type {@link MultipartFile} unless annotated with {@code @RequestParam}
* <li>of type {@code javax.servlet.http.Part} unless annotated with {@code @RequestParam}
* </ul>
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {
if (parameter.hasParameterAnnotation(RequestPart.class)) {
return true;
}
else {
if (parameter.hasParameterAnnotation(RequestParam.class)){
return false;
}
else if (MultipartFile.class == parameter.getParameterType()) {
return true;
}
else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
return true;
}
else {
return false;
}
}
}
示例5: handle
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@SuppressWarnings("unused")
public void handle(@RequestPart SimpleBean requestPart,
@RequestPart(value="requestPart", required=false) SimpleBean namedRequestPart,
@Valid @RequestPart("requestPart") SimpleBean validRequestPart,
@RequestPart("requestPart") MultipartFile multipartFile,
@RequestPart("requestPart") List<MultipartFile> multipartFileList,
@RequestPart("requestPart") MultipartFile[] multipartFileArray,
int i,
MultipartFile multipartFileNotAnnot,
Part part,
@RequestPart("part") List<Part> partList,
@RequestPart("part") Part[] partArray,
@RequestParam MultipartFile requestParamAnnot,
Optional<MultipartFile> optionalMultipartFile,
Optional<Part> optionalPart,
@RequestPart("requestPart") Optional<SimpleBean> optionalRequestPart) {
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:RequestPartMethodArgumentResolverTests.java
示例6: params
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
public void params(@RequestParam(name = "name", defaultValue = "bar") String param1,
@RequestParam("name") String[] param2,
@RequestParam("name") Map<?, ?> param3,
@RequestParam("mfile") MultipartFile param4,
@RequestParam("mfilelist") List<MultipartFile> param5,
@RequestParam("mfilearray") MultipartFile[] param6,
@RequestParam("pfile") Part param7,
@RequestParam("pfilelist") List<Part> param8,
@RequestParam("pfilearray") Part[] param9,
@RequestParam Map<?, ?> param10,
String stringNotAnnot,
MultipartFile multipartFileNotAnnot,
List<MultipartFile> multipartFileList,
Part part,
@RequestPart MultipartFile requestPartAnnot,
@RequestParam("name") String paramRequired,
@RequestParam(name = "name", required = false) String paramNotRequired,
@RequestParam("name") Optional<Integer> paramOptional) {
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RequestParamMethodArgumentResolverTests.java
示例7: uploadMods
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@RequestMapping(value = "/mods", method = RequestMethod.POST)
public UploadModsResponse uploadMods(@RequestPart("files") MultipartFile[] modFiles)
throws IOException, MccyException {
LOG.debug("Upload mods provided: {}", modFiles);
UploadModsResponse response = new UploadModsResponse();
for (MultipartFile modFile : modFiles) {
try {
response.getMods().add(modsService.ingest(modFile));
} catch (MccyException | IOException e) {
UploadModsResponse.Failed failed = new UploadModsResponse.Failed();
failed.setReason(e.getMessage()+"("+e.getClass()+")");
failed.setFilename(modFile.getOriginalFilename());
response.addFailed(failed);
LOG.warn("Failed to ingest {}", e, modFile);
}
}
return response;
}
示例8: addStaticResource
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@RequestMapping(value = Constants.BASEURL_REST
+ "/static/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addStaticResource(@PathVariable String siteUrl, @RequestPart("file") Part file, @RequestParam String path) {
String originalFileName = file.getSubmittedFileName();
if(originalFileName != null) {
try {
String fileName = fileSystemUtil.addStaticResource(getSite(siteUrl), path, file.getInputStream());
logger.debug("Static resource added successful: {}", fileName);
return Response.ok(fileName);
} catch (Exception e) {
return Response.error(e.getMessage());
}
} else {
return Response.error("Empty file.");
}
}
示例9: supportsParameter
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
/**
* Supports the following:
* <ul>
* <li>Annotated with {@code @RequestPart}
* <li>Of type {@link MultipartFile} unless annotated with {@code @RequestParam}.
* <li>Of type {@code javax.servlet.http.Part} unless annotated with {@code @RequestParam}.
* </ul>
*/
public boolean supportsParameter(MethodParameter parameter) {
if (parameter.hasParameterAnnotation(RequestPart.class)) {
return true;
}
else {
if (parameter.hasParameterAnnotation(RequestParam.class)){
return false;
}
else if (MultipartFile.class.equals(parameter.getParameterType())) {
return true;
}
else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
return true;
}
else {
return false;
}
}
}
示例10: hasAuthority
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PreAuthorize("hasRole('ROLE_ADMIN') or hasAuthority('problem_add')")
@RequestMapping(value = "/problems", method = RequestMethod.POST)
public ProblemDetailView addProblem(@RequestPart("problem") ProblemDetailView problemDetailView,
@RequestParam(value = "contentFile",
required = false) MultipartFile contentFile)
throws FormException, IOException {
String contentType = null;
byte[] content = null;
if (contentFile != null) {
contentType = contentFile.getContentType();
content = Base64.getEncoder().encode(contentFile.getBytes());
}
problemDetailDao.createProblem(problemDetailView, contentType, content);
return problemDetailView;
}
示例11: hasPermission
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(@problemsEndpoint.getProblemGroupCodes(#problemCode), 'problem_change')")
@RequestMapping(value = "/problems/{problemCode}", method = RequestMethod.PUT)
@CacheEvict(value = "group_problems", allEntries = true)
public ProblemDetailView editProblem(@PathVariable("problemCode") String problemCode,
@RequestPart("problem") ProblemDetailView problemDetailView,
@RequestParam(value = "contentFile", required = false) MultipartFile contentFile)
throws FormException, IOException {
String contentType = null;
byte[] content = null;
if (contentFile != null) {
contentType = contentFile.getContentType();
content = Base64.getEncoder().encode(contentFile.getBytes());
}
problemDetailDao.editProblem(problemCode, problemDetailView, contentType, content);
return problemDetailView;
}
示例12: uploadKey
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@AuthenticationRequired
@RequestMapping(value = "certificates/pem", method = RequestMethod.POST, produces = { "application/json" })
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public CertificateStatus uploadKey(HttpServletRequest request,
HttpServletResponse response,
@RequestPart(value = "file") MultipartFile file,
@RequestPart(value = "bundle") MultipartFile bundle,
@RequestPart(value = "key") MultipartFile key,
@RequestParam(value = "passphrase") String passphrase)
throws AccessDeniedException, UnauthorizedException,
SessionTimeoutException {
return replaceKey(request, response, file, bundle, key, passphrase,
null);
}
示例13: create
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PostMapping(API_BASE_PATH + "/images")
Mono<Void> create(@RequestPart Flux<FilePart> images) {
return images
.map(image -> {
log.info("We will save " + image +
" to a Reactive database soon!");
return image;
})
.then();
}
示例14: createFile
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PostMapping(value = BASE_PATH)
public Mono<String> createFile(
@RequestPart("file") Flux<FilePart> files,
@AuthenticationPrincipal Principal principal) {
return imageService.createImage(files, principal)
.then(Mono.just("redirect:/"));
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:8,代码来源:UploadController.java
示例15: createFile
import org.springframework.web.bind.annotation.RequestPart; //导入依赖的package包/类
@PostMapping(value = BASE_PATH)
public Mono<String> createFile(
@RequestPart("file") Flux<FilePart> files,
@AuthenticationPrincipal Principal principal) {
return imageService.createImage(files, principal)
.then(Mono.just("redirect:/"));
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:8,代码来源:UploadController.java