本文整理匯總了Java中org.springframework.web.bind.annotation.PutMapping類的典型用法代碼示例。如果您正苦於以下問題:Java PutMapping類的具體用法?Java PutMapping怎麽用?Java PutMapping使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PutMapping類屬於org.springframework.web.bind.annotation包,在下文中一共展示了PutMapping類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/{id}")
public Mono<Post> update(@PathVariable("id") String id, @RequestBody Post post) {
return this.posts.findById(id)
.map(p -> {
p.setTitle(post.getTitle());
p.setContent(post.getContent());
return p;
})
.flatMap(p -> this.posts.save(p));
}
示例2: updateEmployee
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/employees/{id}")
ResponseEntity<?> updateEmployee(@RequestBody Employee employee, @PathVariable long id) {
Employee employeeToUpdate = employee;
employeeToUpdate.setId(id);
Employee updatedEmployee = repository.save(employeeToUpdate);
return new Resource<>(updatedEmployee,
linkTo(methodOn(EmployeeController.class).findOne(updatedEmployee.getId())).withSelfRel()
.andAffordance(afford(methodOn(EmployeeController.class).updateEmployee(null, updatedEmployee.getId())))
.andAffordance(afford(methodOn(EmployeeController.class).deleteEmployee(updatedEmployee.getId()))),
linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")
).getId()
.map(Link::getHref)
.map(href -> {
try {
return new URI(href);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
})
.map(uri -> ResponseEntity.noContent().location(uri).build())
.orElse(ResponseEntity.badRequest().body("Unable to update " + employeeToUpdate));
}
示例3: updateUser
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping(value = "/{id}")
public ResponseEntity<User> updateUser(@PathVariable("id") long id, @RequestBody User user) {
logger.info("Updating User: {} ", user);
Optional<User> optionalUser = userService.findById(id);
if (optionalUser.isPresent()) {
User currentUser = optionalUser.get();
currentUser.setUsername(user.getUsername());
currentUser.setAddress(user.getAddress());
currentUser.setEmail(user.getEmail());
userService.updateUser(currentUser);
return ResponseEntity.ok(currentUser);
}
else {
logger.warn("User with id :{} doesn't exists", id);
return ResponseEntity.notFound().build();
}
}
示例4: updateXmEntity
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
/**
* PUT /xm-entities : Updates an existing xmEntity.
* @param xmEntity the xmEntity to update
* @return the ResponseEntity with status 200 (OK) and with body the updated xmEntity, or with
* status 400 (Bad Request) if the xmEntity is not valid, or with status 500 (Internal
* Server Error) if the xmEntity couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/xm-entities")
@Timed
public ResponseEntity<XmEntity> updateXmEntity(@Valid @RequestBody XmEntity xmEntity) throws URISyntaxException {
log.debug("REST request to update XmEntity : {}", xmEntity);
if (xmEntity.getId() == null) {
return createXmEntity(xmEntity);
}
XmEntity result = xmEntityService.save(xmEntity);
if (Constants.ACCOUNT_TYPE_KEY.equals(xmEntity.getTypeKey())) {
produceEvent(result, Constants.UPDATE_ACCOUNT);
}
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, xmEntity.getId().toString()))
.body(result);
}
示例5: updateBook
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/books/{ISBN}")
public ResponseEntity<Book> updateBook(@PathVariable long ISBN, @RequestBody Book book) {
// search for the book
System.out.println("request reached");
Book book_searched = bookDAO.getBook(ISBN);
if (book_searched == null) {
return new ResponseEntity(HttpStatus.NOT_FOUND);
}
bookDAO.updateBook(ISBN, book.getPrice());
book_searched.setPrice(book.getPrice());
return new ResponseEntity(book_searched, HttpStatus.OK);
}
示例6: updateUserLogins
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
/**
* PUT /account/logins : Updates an existing Account logins.
*
* @param user the user to update
* @return the ResponseEntity with status 200 (OK) and with body the updated user, or with
* status 400 (Bad Request) if the login or email is already in use, or with status 500
* (Internal Server Error) if the user couldn't be updated
*/
@PutMapping("/account/logins")
@Timed
public ResponseEntity<UserDTO> updateUserLogins(@Valid @RequestBody UserDTO user) {
user.getLogins().forEach(
userLogin -> userLoginRepository.findOneByLoginIgnoreCaseAndUserIdNot(
userLogin.getLogin(), user.getId()).ifPresent(s -> {
throw new BusinessException(LOGIN_IS_USED_ERROR_TEXT);
}));
Optional<UserDTO> updatedUser = userService.updateUserLogins(TenantContext.getCurrent().getUserKey(),
user.getLogins());
updatedUser.ifPresent(userDTO -> produceEvent(userDTO, Constants.UPDATE_PROFILE_EVENT_TYPE));
return ResponseUtil.wrapOrNotFound(updatedUser,
HeaderUtil.createAlert("userManagement.updated", user.getUserKey()));
}
示例7: updateSpeaker
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping(value = "/{id}")
public void updateSpeaker(@PathVariable long id, @Validated @RequestBody SpeakerDto speakerDto) {
speakerRepository.findOne(id).ifPresent(
speaker -> {
speaker.setCompany(speakerDto.getCompany());
speaker.setName(speakerDto.getName());
speakerRepository.save(speaker);
}
);
}
示例8: list
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/read/tasks")
@ApiOperation(value = "任務列表")
@RequiresPermissions("sys.task.scheduled.read")
public Object list(ModelMap modelMap) {
Parameter parameter = new Parameter(getService(), "getAllTaskDetail");
List<?> records = provider.execute(parameter).getList();
modelMap.put("recordsTotal", records.size());
modelMap.put("total", records.size());
modelMap.put("current", 1);
modelMap.put("size", records.size());
return setSuccessModelMap(modelMap, records);
}
示例9: findMappingAnnotation
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
Annotation findMappingAnnotation(AnnotatedElement element) {
Annotation mappingAnnotation = element.getAnnotation(RequestMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(GetMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PostMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PutMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(DeleteMapping.class);
if (mappingAnnotation == null) {
mappingAnnotation = element.getAnnotation(PatchMapping.class);
}
}
}
}
}
if (mappingAnnotation == null) {
if (element instanceof Method) {
Method method = (Method) element;
mappingAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
} else {
Class<?> clazz = (Class<?>) element;
mappingAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);
}
}
return mappingAnnotation;
}
示例10: getFireLog
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/read/log")
@ApiOperation(value = "任務執行記錄")
@RequiresPermissions("sys.task.log.read")
public Object getFireLog(ModelMap modelMap, @RequestBody Map<String, Object> log) {
Page<?> list = scheduledService.queryLog(log);
return setSuccessModelMap(modelMap, list);
}
示例11: follow
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/users/{followableUserId}/followers/{followerUserId}")
public ResponseEntity follow(
@PathVariable("followableUserId") String followableUserId,
@PathVariable("followerUserId") String followerUserId
) {
FollowRequest followRequest = new FollowRequest(followerUserId, followableUserId);
followUseCase.execute(followRequest);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
示例12: query
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@ApiOperation(value = "查詢字典項")
@RequiresPermissions("sys.base.dic.read")
@PutMapping(value = "/read/list")
public Object query(ModelMap modelMap, @RequestBody Map<String, Object> param) {
param.put("orderBy", "sort_no");
return super.query(modelMap, param);
}
示例13: usingPutMapping
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping(
path = "usingPutMapping/{targetName}",
consumes = {"text/plain", "application/*"},
produces = {"text/plain", "application/*"})
public String usingPutMapping(@RequestBody User srcUser, @RequestHeader String header,
@PathVariable String targetName, @RequestParam(name = "word") String word, @RequestAttribute String form) {
return String.format("%s %s %s %s %s", srcUser.name, header, targetName, word, form);
}
示例14: updateSelfAvatar
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@Timed
@PutMapping(path = "/xm-entities/self/avatar", consumes = "image/*")
public ResponseEntity<Void> updateSelfAvatar(
@RequestHeader(value = XM_HEADER_CONTENT_NAME, required = false) String fileName,
HttpServletRequest request) throws IOException {
HttpEntity<Resource> avatarEntity = XmHttpEntityUtils.buildAvatarHttpEntity(request, fileName);
URI uri = xmEntityService.updateSelfAvatar(avatarEntity);
return buildAvatarUpdateResponse(uri);
}
示例15: resendStaffNotifications
import org.springframework.web.bind.annotation.PutMapping; //導入依賴的package包/類
@PutMapping("/claim/{referenceNumber}/event/{event}/resend-staff-notifications")
@ApiOperation("Resend staff notifications associated with provided event")
public void resendStaffNotifications(
@PathVariable("referenceNumber") String referenceNumber,
@PathVariable("event") String event,
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorisation
) throws ServletRequestBindingException {
Claim claim = claimService.getClaimByReference(referenceNumber)
.orElseThrow(() -> new NotFoundException(CLAIM + referenceNumber + " does not exist"));
switch (event) {
case "claim-issued":
resendStaffNotificationsOnClaimIssued(claim, authorisation);
break;
case "more-time-requested":
resendStaffNotificationOnMoreTimeRequested(claim);
break;
case "response-submitted":
resendStaffNotificationOnDefendantResponseSubmitted(claim);
break;
case "ccj-request-submitted":
resendStaffNotificationCCJRequestSubmitted(claim);
break;
case "offer-accepted":
resendStaffNotificationOnOfferAccepted(claim);
break;
default:
throw new NotFoundException("Event " + event + " is not supported");
}
}