当前位置: 首页>>代码示例>>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;未经允许,请勿转载。