當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatus.CREATED屬性代碼示例

本文整理匯總了Java中org.springframework.http.HttpStatus.CREATED屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.CREATED屬性的具體用法?Java HttpStatus.CREATED怎麽用?Java HttpStatus.CREATED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.springframework.http.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.CREATED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: save

@RequestMapping(method = POST)
public ResponseEntity<?> save(@RequestBody NotifierBuilder ... cmds) {
    Optional<NotifierBuilder> invalidBuilder = Arrays.stream(cmds).filter(builder -> !builder.isValid()).findFirst();

    if (invalidBuilder.isPresent()) {
        Map<String, Object> result = new HashMap<>();
        result.put("builder", invalidBuilder.get());
        result.put("errors", invalidBuilder.get().validate());
        return new ResponseEntity<Object>(result, HttpStatus.BAD_REQUEST);
    }

    Set<Notifier> notifiers = Arrays.stream(cmds).map(builder -> builder.build()).collect(Collectors.toSet());
    notifiersRepository.save(notifiers);

    HttpHeaders httpHeaders = new HttpHeaders();
    notifiers.stream().forEach(notifier ->
        httpHeaders.add("Location", linkTo(NotifiersController.class).slash(notifier.getName()).toString())
    );
    return new ResponseEntity<Void>(httpHeaders, HttpStatus.CREATED);
}
 
開發者ID:gilles-stragier,項目名稱:quickmon,代碼行數:20,代碼來源:NotifiersController.java

示例2: addPost

/**
 * Create a new post. The post will be validated using {@link PostValidator}.
 *
 * @param post The post to create.
 * @return The newly created post.
 */
@ApiOperation("Create a new post")
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Post> addPost(@Valid @RequestBody Post post) {
    post.setUuid(null);

    try {
        Post saved = postRepository.save(post);
        return ResponseEntity
            .created(URI.create("/admin/posts/" + saved.getUuid()))
            .body(saved);
    } catch (Exception e) {
        logger.error("Could not create post.", e);
        throw new PostCreationException("Could not create post.", e);
    }
}
 
開發者ID:BakkerTom,項目名稱:happy-news,代碼行數:22,代碼來源:AdminPostController.java

示例3: create

@PostMapping
public HttpEntity<FooResource> create(@RequestBody FooResource fooResource) {
	HttpHeaders headers = new HttpHeaders();
	Foo entity = new Foo(fooResource.getUuid(), "Foo");

	// ...

	headers.setLocation(entityLinks.linkForSingleResource(FooResource.class, encode(entity.getId())).toUri());
	return new ResponseEntity<>(headers, HttpStatus.CREATED);
}
 
開發者ID:Devskiller,項目名稱:friendly-id,代碼行數:10,代碼來源:FooController.java

示例4: add

/**
 * Add user with the specified information.
 *
 * @param userVO
 * @return A non-null user.
 */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<User> add(@RequestBody UserVO userVO) {
    logger.info(String.format("user-service add() invoked: %s for %s", userService.getClass().getName(), userVO.getName()));
    System.out.println(userVO);
    User user = new User(null, null, null, null, null);
    BeanUtils.copyProperties(userVO, user);
    try {
        userService.add(user);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Exception raised add User REST Call {0}", ex);
        return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
    }
    return new ResponseEntity<>(HttpStatus.CREATED);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Microservices-with-Java-9-Second-Edition,代碼行數:20,代碼來源:UserController.java

示例5: create

@Authorize(scopes = "policies:create")
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "/v1/policies", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public PasswordPolicyRepresentation create(@RequestBody PasswordPolicyRepresentation representation) {
	PasswordPolicy policy = converter.convert(representation);
	PasswordPolicy created = policyService.create(policy).orThrow();
	return converter.convert(policyService.findById(created.getId()).orThrow());
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:8,代碼來源:PasswordPoliciesEndpoint.java

示例6: postClass

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> postClass(JwtAuthenticationToken token, @RequestBody Class klass) {
  UserContext userContext = (UserContext) token.getPrincipal();
  Class saved = classService.save(userContext.getTenantId(), userContext.getOrgId(), klass);
  HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.setLocation(ServletUriComponentsBuilder
      .fromCurrentRequest().path("/{id}")
      .buildAndExpand(saved.getSourcedId()).toUri());
  return new ResponseEntity<>(saved, httpHeaders, HttpStatus.CREATED);
}
 
開發者ID:Apereo-Learning-Analytics-Initiative,項目名稱:OpenLRW,代碼行數:10,代碼來源:ClassController.java

示例7: add

/**
 * Add booking with the specified information.
 *
 * @param bookingVO
 * @return A non-null booking.
 */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Booking> add(@RequestBody BookingVO bookingVO) {
    logger.info(String.format("booking-service add() invoked: %s for %s", bookingService.getClass().getName(), bookingVO.getName()));
    System.out.println(bookingVO);
    Booking booking = new Booking(null, null, null, null, null, null, null);
    BeanUtils.copyProperties(bookingVO, booking);
    try {
        bookingService.add(booking);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Exception raised add Booking REST Call {0}", ex);
        return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
    }
    return new ResponseEntity<>(HttpStatus.CREATED);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Microservices-with-Java-9-Second-Edition,代碼行數:20,代碼來源:BookingController.java

示例8: create

@Authorize(scopes = "roles:create")
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "/v1/roles", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public RoleRepresentation create(@RequestBody RoleRepresentation representation) {
	Role role = roleConversionService.convert(representation);
	Role created = roleService.create(role).orThrow();
	return roleConversionService.convert(roleService.findById(created.getId()).orThrow());
}
 
開發者ID:PatternFM,項目名稱:tokamak,代碼行數:8,代碼來源:RolesEndpoint.java

示例9: create

@ApiOperation("創建目錄")
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.CREATED)
public BaseResponse create(@RequestBody MenuCreateRequest request){
    log.debug(MenuCreateRequest.class.getSimpleName() + " request received");

    MenuCreateCommand command = new MenuCreateCommand(createAudit(), request);
    UCError error = commandGateway.sendAndWait(command);
    if (error != null) {
        throw new BusinessException(error);
    }
    log.debug(OrgUpdateCommand.class.getSimpleName() + " sent to command gateway: menu [{}] ", command.getId());

    return BaseResponse.create();
}
 
開發者ID:weechang,項目名稱:Taroco,代碼行數:15,代碼來源:MenuController.java

示例10: createStockHotPlate

@PostMapping("/stock-hot-plates")
@ResponseStatus(HttpStatus.CREATED)
public StockHotPlate createStockHotPlate(@RequestBody StockHotPlate stockHotPlateRequest) {
	return stockHotPlateRepository.save(stockHotPlateRequest);
}
 
開發者ID:wengwh,項目名稱:plumdo-stock,代碼行數:5,代碼來源:StockHotPlateResource.java

示例11: usersPost

@Override
@PreAuthorize("hasAuthority('admin')")
public ResponseEntity<Object> usersPost(@ApiParam(value = "The user to save") @Valid @RequestBody UserReg user, Errors errors) throws ApiException, Exception {
    if (errors.hasErrors()) { //Check for validation error from UserReg class(package:model) 
        Error error = new Error();
        error.setError("400");
        error.setMessage("Validation Failed");
        System.out.println("" + errors.getAllErrors());
        return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
    }
    //Call method for save user in database from class UsersService.
    com.jrtechnologies.yum.data.entity.User userEntity = userService.usersPost(user);
    //After created return id of new user.
    return new ResponseEntity<>(userEntity.getId(), HttpStatus.CREATED);
}
 
開發者ID:jrtechnologies,項目名稱:yum,代碼行數:15,代碼來源:UsersApiController.java

示例12: reportMeasure

public ResponseEntity<Object> reportMeasure(@ApiParam(value = "measure reported by the sensor", required=true) @RequestBody Measure measure) {
    // do some magic!
    measureRepository.save(measure);
    return new ResponseEntity<Object>(HttpStatus.CREATED);
}
 
開發者ID:openaffect,項目名稱:openaffect-server,代碼行數:5,代碼來源:MeasuresApiController.java

示例13: upload

@RequestMapping(path = "/upload", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public Resource<PackageMetadata> upload(@RequestBody UploadRequest uploadRequest) {
	return this.packageMetadataResourceAssembler.toResource(this.packageService.upload(uploadRequest));
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:5,代碼來源:PackageController.java

示例14: add

@PutMapping("/upload/image")
public ResponseEntity add(@RequestBody MultipartFile file) throws IOException, InterruptedException, DigestException, NoSuchAlgorithmException {
    return new ResponseEntity<>("image/" + utils.addFile(file).getKeyFile(), HttpStatus.CREATED);
}
 
開發者ID:MrChebik,項目名稱:OSPicture,代碼行數:4,代碼來源:UploadController.java

示例15: uploadImage

/**
 * Uploading image to the system.
 */
@PostMapping("/upload")
public ResponseEntity uploadImage(@RequestParam("file") final MultipartFile uploadedFile) {
    log.info("uploading image: \"" + uploadedFile.getOriginalFilename() + "\"");
    return new ResponseEntity<>(imageService.upload(uploadedFile), HttpStatus.CREATED);
}
 
開發者ID:akraskovski,項目名稱:product-management-system,代碼行數:8,代碼來源:ImageController.java


注:本文中的org.springframework.http.HttpStatus.CREATED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。