下面列出了怎么用org.springframework.web.bind.annotation.DeleteMapping的API类实例代码及写法,或者点击链接到github查看源代码。
@ResponseBody
@DeleteMapping("/delete")
public Result delete(@RequestParam(name = "id") String id) {
Result result = new Result();
OSSFile file = ossFileService.getById(id);
if (file == null) {
result.error500("未找到对应实体");
}
else {
boolean ok = ossFileService.delete(file);
if (ok) {
result.success("删除成功!");
}
}
return result;
}
@ApiOperation(value = "Delete a form deployment", tags = { "Form Deployments" })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Indicates the form deployment was found and has been deleted. Response-body is intentionally empty."),
@ApiResponse(code = 404, message = "Indicates the requested form deployment was not found.")
})
@DeleteMapping(value = "/form-repository/deployments/{deploymentId}", produces = "application/json")
public void deleteFormDeployment(@ApiParam(name = "deploymentId") @PathVariable String deploymentId, HttpServletResponse response) {
FormDeployment deployment = formRepositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment == null) {
throw new FlowableObjectNotFoundException("Could not find a Form deployment with id '" + deploymentId);
}
if (restApiInterceptor != null) {
restApiInterceptor.deleteDeployment(deployment);
}
formRepositoryService.deleteDeployment(deploymentId);
response.setStatus(HttpStatus.NO_CONTENT.value());
}
/**
* Delete users API
*
* @param userIds List of user identifiers
* @param usernames List of usernames
* @return Response object
*/
@DeleteMapping()
public ResponseBody deleteUser(
@RequestParam(value = REQUEST_PARAM_ID, required = false) List<Long> userIds,
@RequestParam(value = REQUEST_PARAM_USERNAME, required = false) List<String> usernames)
throws ServiceLayerException, AuthenticationException, UserNotFoundException {
ValidationUtils.validateAnyListNonEmpty(userIds, usernames);
userService.deleteUsers(userIds != null? userIds : Collections.emptyList(),
usernames != null? usernames : Collections.emptyList());
ResponseBody responseBody = new ResponseBody();
Result result = new Result();
result.setResponse(DELETED);
responseBody.setResult(result);
return responseBody;
}
@ApiOperation(value = "Delete a candidate starter from a process definition", tags = { "Process Definitions" })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Indicates the process definition was found and the identity link was removed. The response body is intentionally empty."),
@ApiResponse(code = 404, message = "Indicates the requested process definition was not found or the process definition does not have an identity-link that matches the url.")
})
@DeleteMapping(value = "/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}")
public void deleteIdentityLink(@ApiParam(name = "processDefinitionId") @PathVariable("processDefinitionId") String processDefinitionId,
@ApiParam(name = "family") @PathVariable("family") String family, @ApiParam(name = "identityId") @PathVariable("identityId") String identityId,
HttpServletResponse response) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
validateIdentityLinkArguments(family, identityId);
// Check if identitylink to delete exists
IdentityLink link = getIdentityLink(family, identityId, processDefinition.getId());
if (link.getUserId() != null) {
repositoryService.deleteCandidateStarterUser(processDefinition.getId(), link.getUserId());
} else {
repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), link.getGroupId());
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
@ApiOperation(value = "Delete a deadletter job", tags = { "Jobs" })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Indicates the job was found and has been deleted. Response-body is intentionally empty."),
@ApiResponse(code = 404, message = "Indicates the requested job was not found.")
})
@DeleteMapping("/cmmn-management/deadletter-jobs/{jobId}")
public void deleteDeadLetterJob(@ApiParam(name = "jobId") @PathVariable String jobId, HttpServletResponse response) {
Job job = getDeadLetterJobById(jobId);
try {
managementService.deleteDeadLetterJob(job.getId());
} catch (FlowableObjectNotFoundException aonfe) {
// Re-throw to have consistent error-messaging across REST-api
throw new FlowableObjectNotFoundException("Could not find a job with id '" + jobId + "'.", Job.class);
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
@DeleteMapping("/rule/{id}")
@AuthAction(PrivilegeType.DELETE_RULE)
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
if (id == null) {
return Result.ofFail(-1, "id cannot be null");
}
AuthorityRuleEntity oldEntity = repository.findById(id);
if (oldEntity == null) {
return Result.ofSuccess(null);
}
try {
repository.delete(id);
} catch (Exception e) {
return Result.ofFail(-1, e.getMessage());
}
if (!publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort())) {
logger.error("Publish authority rules failed after rule delete");
}
return Result.ofSuccess(id);
}
@DeleteMapping(path = Mapping.URL_TASK_COMMENT)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskCommentRepresentationModel> deleteTaskComment(
@PathVariable String taskCommentId)
throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException,
InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Entry to deleteTaskComment(taskCommentId= {})", taskCommentId);
}
taskService.deleteTaskComment(taskCommentId);
ResponseEntity<TaskCommentRepresentationModel> result = ResponseEntity.noContent().build();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Exit from deleteTaskComment(), returning {}", result);
}
return result;
}
/**
* 删除权限标识
* 参考 /permissions/1
* @param id
*/
@PreAuthorize("hasAuthority('permission:delete/permissions/{id}')")
@ApiOperation(value = "后台管理删除权限标识")
@DeleteMapping("/permissions/{id}")
@LogAnnotation(module="user-center",recordRequestParam=false)
public Result delete(@PathVariable Long id) {
try{
sysPermissionService.delete(id);
return Result.succeed("操作成功");
}catch (Exception ex){
ex.printStackTrace();
return Result.failed("操作失败");
}
}
/**
* 删除记录
* @return
*/
@DeleteMapping("/delete")
public String delete(String id) {
if (StringUtils.isNotBlank(id)) {
ElasticsearchUtil.deleteDataById(indexName, esType, id);
return "删除id=" + id;
} else {
return "id为空";
}
}
/**
* Remove all the {@link Criterion} currently associated with the command.
*
* @param id The id of the command to remove the criteria for
* @throws NotFoundException When no {@link Command} with the given {@literal id} exists
*/
@DeleteMapping(value = "/{id}/clusterCriteria")
@ResponseStatus(HttpStatus.OK)
public void removeAllClusterCriteriaFromCommand(
@PathVariable("id") final String id
) throws NotFoundException {
log.info("Called for command {}", id);
this.persistenceService.removeAllClusterCriteriaForCommand(id);
}
@ApiOperation(value = " Delete a historic process instance", tags = { "History Process" }, nickname = "deleteHistoricProcessInstance")
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Indicates that the historic process instance was deleted."),
@ApiResponse(code = 404, message = "Indicates that the historic process instance could not be found.") })
@DeleteMapping(value = "/history/historic-process-instances/{processInstanceId}")
public void deleteProcessInstance(@ApiParam(name = "processInstanceId") @PathVariable String processInstanceId, HttpServletResponse response) {
HistoricProcessInstance processInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
if (restApiInterceptor != null) {
restApiInterceptor.deleteHistoricProcess(processInstance);
}
historyService.deleteHistoricProcessInstance(processInstanceId);
response.setStatus(HttpStatus.NO_CONTENT.value());
}
@DeleteMapping(path = "/notifications/filters/{id}")
public ResponseEntity<Void> deleteFilter(@PathVariable("id") String id) {
NotificationFilter deleted = filteringNotifier.removeFilter(id);
if (deleted != null) {
return ResponseEntity.ok().build();
} else {
return ResponseEntity.notFound().build();
}
}
@DeleteMapping("/jpa/users/{username}/todos/{id}")
public ResponseEntity<Void> deleteTodo(
@PathVariable String username, @PathVariable long id) {
todoJpaRepository.deleteById(id);
return ResponseEntity.noContent().build();
}
/**
* 批量删除
* @param ids
* @return
*/
@DeleteMapping(value = "/deleteBatch")
public Result<SysUserAgent> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
Result<SysUserAgent> result = new Result<SysUserAgent>();
if(ids==null || "".equals(ids.trim())) {
result.error500("参数不识别!");
}else {
this.sysUserAgentService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!");
}
return result;
}
@ApiImplicitParams( {@ApiImplicitParam(dataType = "String", name = "Authorization", paramType = "header")})
@ApiOperation(value = "Deletes a catalog product", notes = "Deletes a catalog product", tags = {"Catalog"})
@DeleteMapping(value = "/product/{id}")
public ResponseEntity<?> deleteProduct(@RequestParam("id") Long productId) {
productService.deleteProduct(productId);
return new ResponseEntity<>(HttpStatus.OK);
}
@DeleteMapping("/{id}")
@ApiOperation("按主键删除一个")
public ResponseEntity<?> del(@PathVariable ID id) {
Assert.notNull(service, "没有正确注入service层");
OpsUser opsUser = getOpsUser();
service.del(id, opsUser);
return ResponseEntity.success();
}
/**
* 删除
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] ids){
pickAddrService.removeByIds(Arrays.asList(ids));
return ResponseEntity.ok().build();
}
/**
* 批量删除
*
* @param ids
* @return
*/
@DeleteMapping(value = "/deleteBatch")
@ApiOperation(value = "批量删除DEMO", notes = "批量删除DEMO")
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.jeecgDemoService.removeByIds(Arrays.asList(ids.split(",")));
return Result.ok("批量删除成功!");
}
@Log("删除岗位")
@ApiOperation("删除岗位")
@DeleteMapping
@PreAuthorize("@el.check('admin','job:del')")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
try {
jobService.removeByIds(ids);
}catch (Throwable e){
throw new BadRequestException( "所选岗位存在用户关联,请取消关联后再试");
}
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* {@code DELETE /job-sqls/:id} : delete the "id" jobSql.
*
* @param id the id of the jobSqlDTO to delete.
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
*/
@DeleteMapping("/job-sqls/{id}")
public ResponseEntity<Void> deleteJobSql(@PathVariable Long id) {
log.debug("REST request to delete JobSql : {}", id);
jobSqlService.delete(id);
return ResponseEntity.noContent()
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString())).build();
}
/**
* 删除角色
*
* @param id
* @return
*/
@DeleteMapping("/{id}")
@RequireRole(RoleConst.ADMIN)
public Response roleDel(@PathVariable Integer id) {
SysRole sysRole = sysRoleService.getById(id);
sysRole.setDelFlag(CommonConstant.STATUS_DEL);
return Response.success(sysRoleService.updateById(sysRole));
}
@DeleteMapping( value = "/{id}" )
public void deleteRelationship( @PathVariable String id, HttpServletRequest request, HttpServletResponse response
)
throws WebMessageException
{
Relationship relationship = relationshipService.getRelationshipByUid( id );
if ( relationship == null )
{
throw new WebMessageException( notFound( "No relationship with id '" + id + "' was found." ) );
}
webMessageService.send( WebMessageUtils.importSummary( relationshipService.deleteRelationship( id ) ), response,
request );
}
@DeleteMapping("/{countryCode}/language/{language}")
public ResponseEntity<?> deleteLanguage(@PathVariable String countryCode,
@PathVariable String language){
try {
cLanguageDao.deleteLanguage(countryCode, language);;
return ResponseEntity.ok().build();
}catch(Exception ex) {
System.out.println("Error occurred while deleting language : {}, for country: {}"+
language+ countryCode+ ex);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error occurred while deleting the language");
}
}
private String resolveApiName(OperationContext context) {
Api api = context.findControllerAnnotation(Api.class).orNull();
if (api != null) {
return api.tags()[0];
}
GetMapping getMapping = context.findControllerAnnotation(GetMapping.class).orNull();
if (getMapping != null) {
return getMapping.name();
}
PostMapping postMapping = context.findControllerAnnotation(PostMapping.class).orNull();
if (postMapping != null) {
return postMapping.name();
}
DeleteMapping deleteMapping = context.findControllerAnnotation(DeleteMapping.class).orNull();
if (deleteMapping != null) {
return deleteMapping.name();
}
PutMapping putMapping = context.findControllerAnnotation(PutMapping.class).orNull();
if (putMapping != null) {
return putMapping.name();
}
RequestMapping requestMapping = context.findControllerAnnotation(RequestMapping.class).orNull();
if (requestMapping != null) {
return requestMapping.name();
}
return "";
}
/**
* 删除配置
*/
@SysLog("删除配置")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys:config:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] configIds){
sysConfigService.deleteBatch(configIds);
return ResponseEntity.ok().build();
}
/**
* 批量删除
* @param ids
* @return
*/
@DeleteMapping(value = "/deleteBatch")
public Result<JoaDemo> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
Result<JoaDemo> result = new Result<JoaDemo>();
if(ids==null || "".equals(ids.trim())) {
result.error500("参数不识别!");
}else {
this.joaDemoService.removeByIds(Arrays.asList(ids.split(",")));
result.success("删除成功!");
}
return result;
}
/**
* DELETE /users/:login : delete the "login" User.
*
* @param login the login of the user to delete
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("/user/{login:" + Constants.LOGIN_REGEX + "}")
@Timed
public ResponseEntity<Void> deleteUser(@PathVariable String login) {
log.debug("REST request to delete User: {}", login);
userService.deleteUser(login);
return ResponseEntity.ok().headers(HeaderUtil.createAlert( "A user is deleted with identifier " + login, login)).build();
}
/**
* Deletes a cache by its key and Id.
*
* @param cacheKey The cache key
* @param cacheId The cache Id
* @return {@link ResponseEntity}
*/
@ResponseBody
@ApiOperation(value = "Delete Cache")
@DeleteMapping(value = "/{cacheKey}/{cacheId}")
@PreAuthorize(ConstantsPrivilege.PRIVILEGE_DELETE_CACHES)
public ResponseEntity<?> delete(@PathVariable("cacheKey") String cacheKey, @PathVariable("cacheId") String cacheId) {
amqpCacheService.dispatchClean(cacheKey, cacheId);
return ResponseEntity.noContent().build();
}
@Operation(summary = "Delete a foo")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "foo deleted"),
@ApiResponse(responseCode = "404", description = "Bad request", content = @Content) })
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteFoo(@Parameter(description = "id of foo to be deleted") @PathVariable("id") long id) {
try {
repository.deleteById(id);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@ApiOperation(value = "DELETE ContentSettingsCropRatio", nickname = "deleteContentSettingsCropRatio", tags = {"content-settings-controller"})
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Created"),
@ApiResponse(code = 401, message = "Unauthorized")})
@DeleteMapping("/plugins/cms/contentSettings/cropRatios/{ratio}")
@RestAccessControl(permission = Permission.SUPERUSER)
public ResponseEntity<SimpleRestResponse<Map>> deleteCropRatio(@PathVariable String ratio) {
logger.debug("REST request - delete content settings crop ratio: {}", ratio);
service.removeCropRatio(ratio.trim());
return ResponseEntity.ok(new SimpleRestResponse<>(new HashMap()));
}