本文整理匯總了Java中org.springframework.http.HttpStatus.OK屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.OK屬性的具體用法?Java HttpStatus.OK怎麽用?Java HttpStatus.OK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.springframework.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.OK屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateUser
@Secured(ADMIN)
@RequestMapping(value = "/user/{id}/update", method = RequestMethod.PUT)
public ResponseEntity<?> updateUser(@PathVariable("id") long id, @RequestBody UserUpdateDTO updateDTO) {
Optional<ValidationErrors> errors = validators.validate(updateDTO);
if (errors.isPresent()) {
log.warn("User update data has field errors.");
return new ResponseEntity<>(errors.get().getErrors(), HttpStatus.BAD_REQUEST);
}
UserDTO updatedUser = userService.updateUser(id, updateDTO);
if (updatedUser == null) {
log.error("No user found with given id({})",id);
return new ResponseEntity<>("User not found with given id.", HttpStatus.INTERNAL_SERVER_ERROR);
} else {
log.debug("User({}) successfully updated by admin.",id);
return new ResponseEntity<>(updatedUser, HttpStatus.OK);
}
}
示例2: getAdaptorConfiguration
@ApiOperation(value = "getAdaptorConfiguration", nickname = "getAdaptorConfiguration")
@RequestMapping(value = "/CISCore/getAdaptorConfiguration", method = RequestMethod.GET)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = AdaptorConfigurationImpl.class),
@ApiResponse(code = 400, message = "Bad Request", response = AdaptorConfigurationImpl.class),
@ApiResponse(code = 500, message = "Failure", response = AdaptorConfigurationImpl.class)})
public ResponseEntity<AdaptorConfigurationImpl> getAdaptorConfiguration() {
log.info("--> getAdaptorConfiguration");
AdaptorConfigurationImpl config = (AdaptorConfigurationImpl)cisCore.getAdaptorConfiguration();
HttpHeaders responseHeaders = new HttpHeaders();
log.info("getAdaptorConfiguration -->");
return new ResponseEntity<AdaptorConfigurationImpl>(config, responseHeaders, HttpStatus.OK);
}
示例3: exportCsv
/**
* Export result to csv
*
* @param requestParams the query of the transfer timing search
* @param pageable the pagination information
* @return downloadable csv
*/
@GetMapping(value = "/transfer-timings.csv", produces = CsvMediaType.TEXT_CSV_VALUE)
@Timed
public ResponseEntity<List<TransferTimingListingDTO>> exportCsv(@RequestParam Map<String, String> requestParams, @ApiParam Pageable pageable) {
/* ==========================
* In this example you might not understand as I did not put the other part of code but I have a AbstractHttpMessageConverter
* that converts object or list of objects to a CSV
* ==========================
*/
final List<TransferTimingListingDTO> list;
if (requestParams != null) {
list = transferTimingPageService.searchWithoutPaging(requestParams, pageable);
} else {
list = transferTimingPageService.getAllWithoutPaging(pageable);
}
String filename = "visual-timings-" + Instant.now().getEpochSecond() + ".csv";
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename);
headers.add("X-Save-As", filename);
return new ResponseEntity<>(list, headers, HttpStatus.OK);
}
示例4: getDeveloperTeams
@Override
public ResponseEntity<?> getDeveloperTeams() {
List<Map<String, String>> developerTeams = new ArrayList<>();
Map<String, String> developerTeam = new LinkedHashMap<>();
developerTeam.put("版權所有", "米斯雲平台");
developerTeam.put("產品設計與研發團隊", "Minsx Cloud Team");
developerTeam.put("界麵與用戶體驗團隊", "Minsx Cloud Team");
developerTeam.put("相關鏈接", "https://www.minsx.com/\thttps://github.com/MinsxCloud");
developerTeam.forEach((key, value) -> {
Map<String, String> item = new LinkedHashMap<>();
item.put("key", key);
item.put("value", value);
developerTeams.add(item);
});
return new ResponseEntity<>(developerTeams, HttpStatus.OK);
}
示例5: ready
@RequestMapping("/ready")
ResponseEntity<String> ready() {
HttpHeaders responseHeaders = new HttpHeaders();
HttpStatus httpStatus;
String ret;
if (ready)
{
httpStatus = HttpStatus.OK;
ret = "ready";
}
else
{
httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
ret = "Service unavailable";
}
ResponseEntity<String> responseEntity = new ResponseEntity<String>(ret, responseHeaders, httpStatus);
return responseEntity;
}
示例6: create
/**
* Function to create a user
* Only a system administrator can create an User
*
* @param user
* @return DtoUser
*/
@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<DtoUser> create(@RequestBody final DtoUser user) {
LOGGER.debug(() -> "Creating User " + user.getEmail());
if (!this.getLoggedInUser().isAdmin()) {
LOGGER.error(() -> "Users can only be created by system administrators");
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
user.setPassword(ENCODER.encode(user.getPassword()));
return new ResponseEntity<>(getDtoUser(serviceUser.addUser(user)), HttpStatus.OK);
}
示例7: findByName
/**
* Fetch restaurants with the specified name. A partial case-insensitive
* match is supported. So <code>http://.../restaurants/rest</code> will find
* any restaurants with upper or lower case 'rest' in their name.
*
* @param name
* @return A non-null, non-empty collection of restaurants.
*/
@HystrixCommand(fallbackMethod = "defaultRestaurants")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Collection<Restaurant>> findByName(@RequestParam("name") String name) {
logger.info(String.format("restaurant-service findByName() invoked:{} for {} ", restaurantService.getClass().getName(), name));
name = name.trim().toLowerCase();
Collection<Restaurant> restaurants;
try {
restaurants = restaurantService.findByName(name);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Exception raised findByName REST Call", ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return restaurants.size() > 0 ? new ResponseEntity<>(restaurants, HttpStatus.OK)
: new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
開發者ID:PacktPublishing,項目名稱:Mastering-Microservices-with-Java-9-Second-Edition,代碼行數:23,代碼來源:RestaurantController.java
示例8: getJobConfig
public ResponseEntity<String> getJobConfig(@ApiParam(value = "Name of the job",required=true ) @PathVariable("name") String name,
@RequestHeader(value = "Accept", required = false) String accept) throws Exception {
// do some magic!
if (accept != null && accept.contains("")) {
return new ResponseEntity<String>(objectMapper.readValue("", String.class), HttpStatus.OK);
}
return new ResponseEntity<String>(HttpStatus.OK);
}
示例9: searchVotes
/**
* SEARCH /_search/votes?query=:query : search for the vote corresponding
* to the query.
*
* @param query the query of the vote search
* @param pageable the pagination information
* @return the result of the search
*/
@GetMapping("/_search/votes")
@Timed
public ResponseEntity<List<Vote>> searchVotes(@RequestParam String query, @ApiParam Pageable pageable) {
log.debug("REST request to search for a page of Votes for query {}", query);
Page<Vote> page = voteSearchRepository.search(queryStringQuery(query), pageable);
HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/votes");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
示例10: query
@ApiOperation("Query product from catalog")
@ApiResponses({
@ApiResponse(code = 201, message = "Product has been query from catalog"),
@ApiResponse(code = 404, message = "Product not found")})
@ResponseStatus(HttpStatus.OK)
@GetMapping("/query")
public ProductDto query(@RequestParam long id) {
return productService.get(id);
}
示例11: showProjectsDetails
@JsonView(JsonViews.Project.class)
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/api/project/details", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json")
public List<Project> showProjectsDetails()
{
LOGGER.debug("ApiController - showProjectsDetails");
return projectService.findAllWithAll();
}
示例12: getParticipantFromCGOR
@ApiOperation(value = "getParticipantFromCGOR", nickname = "getParticipantFromCGOR")
@RequestMapping(value = "/CISConnector/getParticipantFromCGOR/{cgorName}", method = RequestMethod.GET)
@ApiImplicitParams({
@ApiImplicitParam(name = "cgorName", value = "the CGOR name", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "organisation", value = "the Organisation name", required = true, dataType = "String", paramType = "query")
})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = Participant.class),
@ApiResponse(code = 400, message = "Bad Request", response = Participant.class),
@ApiResponse(code = 500, message = "Failure", response = Participant.class)})
public ResponseEntity<Participant> getParticipantFromCGOR(@PathVariable String cgorName, @QueryParam("organisation") String organisation) {
log.info("--> getParticipantFromCGOR: " + cgorName);
Participant participant;
try {
participant = connector.getParticipantFromCGOR(cgorName, organisation);
} catch (CISCommunicationException e) {
log.error("Error executing the request: Communication Error" , e);
participant = null;
}
HttpHeaders responseHeaders = new HttpHeaders();
log.info("getParticipantFromCGOR -->");
return new ResponseEntity<Participant>(participant, responseHeaders, HttpStatus.OK);
}
示例13: getByDates
/**
* GET /audits : get a page of AuditEvents between the fromDate and toDate.
*
* @param fromDate the start of the time period of AuditEvents to get
* @param toDate the end of the time period of AuditEvents to get
* @param pageable the pagination information
* @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
*/
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
@RequestParam(value = "fromDate") LocalDate fromDate,
@RequestParam(value = "toDate") LocalDate toDate,
Pageable pageable) {
Page<AuditEvent> page = auditEventService.findByDates(
fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(),
pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
示例14: getByDates
/**
* GET /audits : get a page of AuditEvents between the fromDate and toDate.
*
* @param fromDate the start of the time period of AuditEvents to get
* @param toDate the end of the time period of AuditEvents to get
* @param pageable the pagination information
* @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
* @throws URISyntaxException if there is an error to generate the pagination HTTP headers
*/
@GetMapping(params = {"fromDate", "toDate"})
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<AuditEvent>> getByDates(
@RequestParam(value = "fromDate") LocalDate fromDate,
@RequestParam(value = "toDate") LocalDate toDate,
@ApiParam Pageable pageable) throws URISyntaxException {
Page<AuditEvent> page = auditEventService.findByDates(fromDate.atTime(0, 0), toDate.atTime(23, 59), pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
示例15: getOrderById
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<?> getOrderById(@PathVariable("id") long id) {
LOGGER.info("Start getOrderById with id: {}", id);
Order order = orderService.getById(id);
if (order == null) {
LOGGER.info("order with id: {} is NULL", id);
return new ResponseEntity<>("Order not found", HttpStatus.NOT_FOUND);
}
OrderDto orderDto = OrderDto.toDto(order);
return new ResponseEntity<>(orderDto, HttpStatus.OK);
}