本文整理汇总了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");
}
}