org.springframework.http.HttpStatus#CREATED源码实例Demo

下面列出了org.springframework.http.HttpStatus#CREATED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SpringCloud-Shop   文件: UserController.java
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<User> save(User user, UriComponentsBuilder ucb) {
    ServiceInstance instance = client.getLocalServiceInstance();
    logger.info("/user, host:" + instance.getHost() + ", serviceId:" + instance.getServiceId() + ",user id:" + user.getId() + ",user name:" + user.getName());

    User saved = userService.save(user);

    HttpHeaders headers = new HttpHeaders();
    URI locationUri = ucb.path("/login/")
            .path(String.valueOf(saved.getId()))
            .build()
            .toUri();
    headers.setLocation(locationUri);

    ResponseEntity<User> responseEntity = new ResponseEntity<>(saved, headers, HttpStatus.CREATED);

    return responseEntity;

}
 
源代码2 项目: kaif   文件: V1ArticleResource.java
@ApiOperation(value = "[article] Create an article with content",
    notes = "Create an article with content in specified zone")
@ResponseStatus(HttpStatus.CREATED)
@RequiredScope(ClientAppScope.ARTICLE)
@RequestMapping(value = "/speak", method = RequestMethod.PUT, consumes = {
    MediaType.APPLICATION_JSON_VALUE })
public V1ArticleDto speak(ClientAppUserAccessToken token, @Valid @RequestBody SpeakEntry entry) {
  return articleService.createSpeak(token, entry.zone, entry.title.trim(), entry.content.trim())
      .toV1Dto();
}
 
源代码3 项目: QuizZz   文件: UserController.java
@RequestMapping(value = "/registration", method = RequestMethod.POST)
@PreAuthorize("permitAll")
public ResponseEntity<User> signUp(@Valid User user, BindingResult result) {

	RestVerifier.verifyModelResult(result);
	User newUser = registrationService.startRegistration(user);

	if (registrationService.isRegistrationCompleted(newUser)) {
		return new ResponseEntity<User>(newUser, HttpStatus.CREATED);
	} else {
		return new ResponseEntity<User>(newUser, HttpStatus.OK);
	}
}
 
源代码4 项目: metron   文件: KafkaController.java
@ApiOperation(value = "Creates a new Kafka topic")
@ApiResponses({
  @ApiResponse(message = "Returns saved Kafka topic", code = 200)
})
@RequestMapping(value = "/topic", method = RequestMethod.POST)
ResponseEntity<KafkaTopic> save(final @ApiParam(name = "topic", value = "Kafka topic", required = true) @RequestBody KafkaTopic topic) throws RestException {
  return new ResponseEntity<>(kafkaService.createTopic(topic), HttpStatus.CREATED);
}
 
@RequestMapping(value = "/reocurringPayment", method = RequestMethod.POST)
public ResponseEntity<String> createReocurringPayment(@RequestBody Map<String, Object> data){
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add("content-type", MediaType.APPLICATION_JSON.toString());

    ResponseEntity<String> response;
    if (paymentGateway.createReocurringPayment((Integer)data.get("amount"))) {
        response = new ResponseEntity<>("{errors: []}", responseHeaders, HttpStatus.CREATED);
    } else {
        response = new ResponseEntity<>("{errors: [\"error1\", \"error2\"]}", responseHeaders, HttpStatus.BAD_REQUEST);
    }

    return response;
}
 
@RequestMapping("/foo")
public ResponseEntity<String> foo(HttpEntity<byte[]> requestEntity) throws UnsupportedEncodingException {
	assertNotNull(requestEntity);
	assertEquals("MyValue", requestEntity.getHeaders().getFirst("MyRequestHeader"));
	String requestBody = new String(requestEntity.getBody(), "UTF-8");
	assertEquals("Hello World", requestBody);

	HttpHeaders responseHeaders = new HttpHeaders();
	responseHeaders.set("MyResponseHeader", "MyValue");
	return new ResponseEntity<String>(requestBody, responseHeaders, HttpStatus.CREATED);
}
 
源代码7 项目: xxproject   文件: RegistrationController.java
@RequestMapping(value = "/user/registration", method = RequestMethod.POST)
@ResponseBody
public ApiError registerUserAccount(@Valid final UserDto accountDto, final HttpServletRequest request) {
    logger.info("Registering user account with information: {}", accountDto);

    final User registered = userService.registerNewUserAccount(accountDto);

    return new ApiError(HttpStatus.CREATED, "user successfully registered");
}
 
/**
 * Logins in the user from the authentication request passed in body.
 * 
 * @param authenticationRequest The request with username and password.
 * @return HTTP status CREATED if successful.
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseStatus( HttpStatus.CREATED )
@ResponseBody
public Map<String, Object> login(@RequestBody AuthenticationRequest authenticationRequest) {
	logger.debug("AuthenticationController.login: login request for username: " + authenticationRequest.getUsername());
	Map<String, Object> authenticationResponse = this.service.login(authenticationRequest.getUsername(), authenticationRequest.getPassword());
	return authenticationResponse;// authToken and accountId;
}
 
@PostMapping
@PreAuthorize("hasRole('USER')")
public ResponseEntity<PostResponse> addPost(@Valid @RequestBody PostRequest postRequest,
		@CurrentUser UserPrincipal currentUser) {
	PostResponse postResponse = postService.addPost(postRequest, currentUser);
	
	return new ResponseEntity<PostResponse>(postResponse, HttpStatus.CREATED);
}
 
源代码10 项目: QuizZz   文件: AnswerController.java
@RequestMapping(value = "", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@ResponseStatus(HttpStatus.CREATED)
public Answer save(@Valid Answer answer, BindingResult result, @RequestParam long question_id) {

	RestVerifier.verifyModelResult(result);

	Question question = questionService.find(question_id);
	return questionService.addAnswerToQuestion(answer, question);
}
 
源代码11 项目: restdocs-raml   文件: TagsController.java
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
HttpHeaders create(@RequestBody TagInput tagInput) {
	Tag tag = new Tag();
	tag.setName(tagInput.getName());

	this.repository.save(tag);

	HttpHeaders httpHeaders = new HttpHeaders();
	httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri());

	return httpHeaders;
}
 
@PreAuthorize("@roleChecker.hasValidRole(#principal)")
@RequestMapping(value="/company", method=RequestMethod.POST, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CompanyDTO> createCompany(
		Principal principal,
		@RequestBody CompanyDTO companyDTO) {
	
	// Check for SUPERADMIN role
	// RoleChecker.hasValidRole(principal);
	
	companyDTO = companyService.create(companyDTO);
	
	return new ResponseEntity<CompanyDTO>(companyDTO, HttpStatus.CREATED);
}
 
源代码13 项目: maintain   文件: InvtsController.java
@RequestMapping("download")
public ResponseEntity<byte[]> download() throws IOException {
	HttpHeaders headers = new HttpHeaders();
	headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
	headers.setContentDispositionFormData("attachment", "README.md");
	File file = new File("README.md");
	System.out.println(file.getAbsolutePath());
	System.out.println(this.getClass().getResource(""));
	return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
}
 
源代码14 项目: bearchoke   文件: UserController.java
/**
 * Register a user with the system
 *
 * @param user user
 * @return
 */
@RequestMapping(value = "/api/user/register", method = {RequestMethod.POST}, produces = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE, consumes = ApplicationMediaType.APPLICATION_BEARCHOKE_V1_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public void register(@RequestBody RegisterUserDto user) {
    // attach default role to user
    user.setRoles(new String[]{PlatformConstants.DEFAULT_USER_ROLE});

    if (log.isDebugEnabled()) {
        log.debug(user.toString());
    }

    commandBus.dispatch(new GenericCommandMessage<>(
                    new RegisterUserCommand(new UserIdentifier(), user))
    );
}
 
源代码15 项目: spring-rest-server   文件: LocationFacade.java
@RequestMapping(value = "/ticket/{ticketId}/scan/{locationId}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public LocationVO addLocationScan(@PathVariable long ticketId, @PathVariable long locationId) {
    Ticket ticket = ticketService.get(ticketId);
    Location location = ticketService.addLocationScan(ticket, locationId);
    return mappingService.map(location, LocationVO.class);
}
 
源代码16 项目: yshopmall   文件: SystemStoreController.java
@PostMapping(value = "/getL")
@Log("获取经纬度")
@ApiOperation("获取经纬度")
@PreAuthorize("@el.check('yxSystemStore:getl')")
public ResponseEntity<Object> create(@Validated @RequestBody String jsonStr){
    String key = RedisUtil.get(ShopKeyUtils.getTengXunMapKey());
    if(StrUtil.isBlank(key)) throw  new BadRequestException("请先配置腾讯地图key");
    JSONObject jsonObject = JSON.parseObject(jsonStr);
    String addr = jsonObject.getString("addr");
    String url = StrUtil.format("?address={}&key={}",addr,key);
    String json = HttpUtil.get(ShopConstants.QQ_MAP_URL+url);
    return new ResponseEntity<>(json,HttpStatus.CREATED);
}
 
源代码17 项目: PhotoAlbum-api   文件: AlbumController.java
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> createAlbum(@Valid @RequestBody AlbumRequest albumRequest) {
  return new ResponseEntity<>(this.albumService.createAlbum(albumRequest), HttpStatus.CREATED);
}
 
@PostMapping(consumes="application/json")
@ResponseStatus(HttpStatus.CREATED)
public Taco postTaco(@RequestBody Taco taco) {
  return tacoRepo.save(taco);
}
 
源代码19 项目: Spring-5.0-By-Example   文件: UserResource.java
@PostMapping
public ResponseEntity<User> newUser(NewsRequest news){
  return new ResponseEntity<>(new User(), HttpStatus.CREATED);
}
 
/**
 * Create a new stream.
 *
 * @param name stream name
 * @param dsl DSL definition for stream
 * @param deploy if {@code true}, the stream is deployed upon creation (default is
 * {@code false})
 * @param description description of the stream definition
 * @return the created stream definition
 * @throws DuplicateStreamDefinitionException if a stream definition with the same name
 * already exists
 * @throws InvalidStreamDefinitionException if there errors in parsing the stream DSL,
 * resolving the name, or type of applications in the stream
 */
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public StreamDefinitionResource save(@RequestParam("name") String name, @RequestParam("definition") String dsl,
										@RequestParam(value = "description", defaultValue = "") String description,
										@RequestParam(value = "deploy", defaultValue = "false") boolean deploy) {
	StreamDefinition streamDefinition = this.streamService.createStream(name, dsl, description, deploy);
	return new Assembler(new PageImpl<>(Collections.singletonList(streamDefinition))).toModel(streamDefinition);
}