public String deletion(@PathVariable("bookId") int bookId, HttpServletRequest request, Model model) throws BSException { Integer bookInfo = commentService.findById(bookId); PageInfo<Comment> books = commentService.findCommentListByCondition(); PageInfo<ReplyComment> replyCommentList = replyCommentService.findAllReplxyComment(); model.addAttribute("commentList", books); model.addAttribute("replyCommentList", replyCommentList); return "admin/comment/list"; }
时间: 2023-06-17 17:03:10 浏览: 188
这段代码是一个Spring Boot Web应用程序中的控制器方法,用于处理删除操作。其中,@PathVariable("bookId")注解表示将URL路径中的bookId参数绑定到方法的bookId参数上。
首先,通过调用commentService的findById()方法查找要删除的评论。然后,通过调用commentService的findCommentListByCondition()方法和replyCommentService的findAllReplxyComment()方法获取评论列表和回复评论列表,并将它们添加到模型中。
最后,返回视图名称为"admin/comment/list",表示删除操作完成后返回到评论列表页面。如果在删除过程中出现了异常,将抛出BSException异常。
相关问题
def delete_selected(modeladmin, request, queryset): """ Default action which deletes the selected objects. This action first displays a confirmation page which shows all the deletable objects, or, if the user has no permission one of the related childs (foreignkeys), a "permission denied" message. Next, it deletes all selected objects and redirects back to the change list. """ opts = modeladmin.model._meta app_label = opts.app_label # Check that the user has delete permission for the actual model if not modeladmin.has_delete_permission(request): raise PermissionDenied using = router.db_for_write(modeladmin.model) # Populate deletable_objects, a data structure of all related objects that # will also be deleted. deletable_objects, model_count, perms_needed, protected = get_deleted_objects( queryset, opts, request.user, modeladmin.admin_site, using) # The user has already confirmed the deletion. # Do the deletion and return a None to display the change list view again. if request.POST.get('post') and not protected: if perms_needed: raise PermissionDenied n = queryset.count() if n: for obj in queryset: obj_display = force_text(obj) modeladmin.log_deletion(request, obj, obj_display) queryset.delete() modeladmin.message_user(request, _("Successfully deleted %(count)d %(items)s.") % { "count": n, "items": model_ngettext(modeladmin.opts, n) }, messages.SUCCESS) # Return None to display the change list page again. return None if len(queryset) == 1: objects_name = force_text(opts.verbose_name) else: objects_name = force_text(opts.verbose_name_plural) if perms_needed or protected: title = _("Cannot delete %(name)s") % {"name": objects_name} else: title = _("Are you sure?") context = dict( modeladmin.admin_site.each_context(request), title=title, objects_name=objects_name, deletable_objects=[deletable_objects], model_count=dict(model_count).items(), queryset=queryset, perms_lacking=perms_needed, protected=protected, opts=opts, action_checkbox_name=helpers.ACTION_CHECKBOX_NAME, media=modeladmin.media, ) request.current_app = modeladmin.admin_site.name # Display the confirmation page return TemplateResponse(request, modeladmin.delete_selected_confirmation_template or [ "admin/%s/%s/delete_selected_confirmation.html" % (app_label, opts.model_name), "admin/%s/delete_selected_confirmation.html" % app_label, "admin/delete_selected_confirmation.html" ], context) delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s")
这段代码定义了一个默认的 Django Admin 后台操作,用于批量删除选中的对象。具体来说,这个操作会首先显示一个确认页面,列出所有将被删除的对象,以及与这些对象相关的其他对象(例如外键关联的对象)。如果用户没有删除权限,或者某些对象受到保护,则会显示一个“无权删除”或“不能删除”的消息。如果用户确认删除操作,则会删除所有选中的对象,并重定向到对象列表页面。
在代码中,`delete_selected()` 函数接受三个参数:`modeladmin` 表示 Django admin 后台的管理器对象,`request` 表示当前的 HTTP 请求对象,`queryset` 表示选中的对象的 QuerySet。函数首先获取模型的元数据信息,然后检查当前用户是否有删除权限。如果没有权限,则会引发 `PermissionDenied` 异常。接下来,函数调用 `get_deleted_objects()` 方法获取所有将被删除的对象及相关对象的信息,并根据用户的选择执行删除操作或者显示确认页面。最后,函数返回一个 `TemplateResponse` 对象,用于显示确认页面或者执行删除操作后的重定向。此外,函数还定义了一个 `short_description` 属性,用于在 Django admin 后台中显示操作名称。
void modifyStudentInfo() { int id, i; Student *student; printf("Please enter the student ID to modify: "); scanf("%d", &id); for (i = 0; i < studentCount; ++i) { if (students[i].id == id) { student = &students[i]; outputStudentInfo(student); inputStudentInfo(student); printf("Modification successful!\n"); return; } } printf("Student with ID %d not found!\n", id); } void deleteStudentInfo() { int id, i; printf("Please enter the student ID to delete: "); scanf("%d", &id); for (i = 0; i < studentCount; ++i) { if (students[i].id == id) { memmove(&students[i], &students[i+1], sizeof(Student) * (studentCount - i - 1)); studentCount--; printf("Deletion successful!\n"); return; } } printf("Student with ID %d not found!\n", id); }
这是两个函数,一个是用于修改学生信息,一个是用于删除学生信息。函数中都有一个输入参数id,用于指定要修改或删除的学生的ID。在函数中,会遍历学生数组,查找是否存在该ID的学生。如果存在,修改函数会输出该学生信息,然后读取新的信息进行修改,修改成功后返回;删除函数会使用memmove函数将该学生的数据从数组中移除,并将学生数量减一,然后返回。如果遍历完整个数组后仍然没有找到该ID的学生,则输出提示信息。
阅读全文