From 259a2fe6fdce2d46a276e138885bb96fd356896e Mon Sep 17 00:00:00 2001 From: Dcx12138 <2320898596@qq.com> Date: Sun, 15 Dec 2024 16:59:52 +0800 Subject: [PATCH] =?UTF-8?q?readme=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SmileToCandy --- .../tamguo/web/member/AccountController.java | 99 ++++++++++--- .../web/member/MemberPaperController.java | 135 ++++++++++++++---- .../tamguo/web/member/QuestionController.java | 112 ++++++++++++--- 3 files changed, 275 insertions(+), 71 deletions(-) diff --git a/tamguo/src/main/java/com/tamguo/web/member/AccountController.java b/tamguo/src/main/java/com/tamguo/web/member/AccountController.java index eac0ff7..f5f989c 100644 --- a/tamguo/src/main/java/com/tamguo/web/member/AccountController.java +++ b/tamguo/src/main/java/com/tamguo/web/member/AccountController.java @@ -35,76 +35,133 @@ import com.tamguo.util.ShiroUtils; import com.tamguo.util.Status; import com.tamguo.util.UploaderMessage; +// 标识这是一个Spring的控制器类,用于处理Web请求并返回相应的视图或数据 @Controller public class AccountController { - + + // 自动注入IMemberService,用于处理会员相关的业务逻辑 @Autowired public IMemberService memberService; + + // 通过配置文件注入文件存储路径属性值,方便后续文件保存操作使用 @Value("${file.storage.path}") private String fileStoragePath; + + // 自动注入Setting,可能用于获取一些系统配置相关的设置信息 @Autowired private Setting setting; + + // 自动注入CacheService,用于缓存相关操作,例如在生成头像编号时使用缓存来保证编号的唯一性和递增性 @Autowired private CacheService cacheService; + // 定义头像编号的默认格式化字符串,用于格式化生成的编号,保证编号格式统一 private static final String AVATOR_NO_FORMAT = "00000"; + // 定义头像编号的前缀,方便识别头像文件相关的编号 private static final String AVATOR_PREFIX = "MTX"; - + + // 创建日志记录器,用于记录该类中关键操作的日志信息,方便调试和问题排查 public Logger logger = LoggerFactory.getLogger(getClass()); + /** + * 处理会员账户页面的GET请求,设置视图名称并从会话中获取当前会员信息,再通过会员服务查询更详细的会员信息后添加到模型中返回视图 + * + * @param model 用于传递数据到视图的ModelAndView对象 + * @param session 当前的HttpSession对象,可从中获取会话相关的属性,如当前会员信息 + * @return 返回包含视图名称和会员相关数据的ModelAndView对象,以便渲染相应的视图展示给用户 + */ @RequestMapping(value = "member/account", method = RequestMethod.GET) - public ModelAndView index(ModelAndView model , HttpSession session){ + public ModelAndView index(ModelAndView model, HttpSession session) { model.setViewName("member/account"); MemberEntity member = (MemberEntity) session.getAttribute("currMember"); - model.addObject("member" , memberService.findByUid(member.getUid())); + model.addObject("member", memberService.findByUid(member.getUid())); return model; } - + + /** + * 处理会员信息更新的POST请求,设置会员的用户ID(可能从安全框架获取当前登录用户ID),然后调用会员服务更新会员信息,并返回更新成功的结果 + * + * @param member 包含要更新的会员信息的MemberEntity对象,通过请求体接收 + * @return 返回表示更新操作结果的Result对象,如果更新成功则包含更新后的会员信息 + */ @RequestMapping(value = "member/account/update", method = RequestMethod.POST) @ResponseBody - public Result updateMember(@RequestBody MemberEntity member){ + public Result updateMember(@RequestBody MemberEntity member) { member.setUid(ShiroUtils.getUserId()); memberService.updateMember(member); return Result.successResult(member); } - + + /** + * 处理会员密码页面的GET请求,仅设置视图名称,用于返回相应的密码修改页面视图给用户 + * + * @param model 用于传递数据到视图的ModelAndView对象(此处未添加额外数据) + * @return 返回包含视图名称的ModelAndView对象,以便渲染密码修改页面视图 + */ @RequestMapping(value = "member/password", method = RequestMethod.GET) - public ModelAndView password(ModelAndView model){ + public ModelAndView password(ModelAndView model) { model.setViewName("member/password"); return model; } - + + /** + * 处理会员密码更新的POST请求,调用会员服务来更新会员密码,并返回相应的更新结果 + * + * @param member 包含要更新密码相关信息的MemberEntity对象,通过请求体接收 + * @return 返回表示密码更新操作结果的Result对象 + */ @RequestMapping(value = "member/password/update", method = RequestMethod.POST) @ResponseBody - public Result updatePwd(@RequestBody MemberEntity member){ + public Result updatePwd(@RequestBody MemberEntity member) { return memberService.updatePwd(member); } - + + /** + * 处理会员上传文件的POST请求,接收上传的文件以及HttpServletRequest对象,实现文件上传功能,包括创建文件存储目录、生成文件名、文件流读写等操作,最后返回文件上传的结果信息 + * + * @param file 上传的MultipartFile类型文件对象,通过请求参数接收 + * @param request 当前的HttpServletRequest对象,可获取请求相关的一些信息(此处可能未使用到,但在某些场景下可能会用到) + * @return 返回包含文件上传状态、提示信息、文件路径等相关信息的UploaderMessage对象,告知前端文件上传的结果情况 + * @throws IOException 如果在文件读写等操作过程中出现I/O异常则抛出 + */ @RequestMapping(value = "/member/uploadFile", method = RequestMethod.POST) @ResponseBody - public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException { + public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException { + // 判断上传的文件是否为空,如果为空则直接返回文件为空的错误提示信息 if (!file.isEmpty()) { InputStream in = null; OutputStream out = null; - + try { + // 根据当前日期构建文件存储的路径,方便按日期分类存储文件 String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd"); File dir = new File(path); + // 如果目录不存在,则创建相应的目录,确保文件有存储的位置 if (!dir.exists()) dir.mkdirs(); + + // 生成头像文件名,结合缓存获取的编号以及原文件名的后缀组成完整的文件名 String avatorName = this.getAvatorNo() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + // 获取文件输入流,用于读取上传文件的内容 in = file.getInputStream(); + // 创建文件输出流,用于将读取的文件内容写入到服务器指定的存储位置 out = new FileOutputStream(path + "/" + avatorName); + byte[] b = new byte[1024]; int len = 0; + // 通过循环读取输入流中的文件内容,并写入到输出流中,实现文件的复制保存操作 while ((len = in.read(b)) > 0) { out.write(b, 0, len); } + // 关闭输出流,释放资源 out.close(); + // 关闭输入流,释放资源 in.close(); + // 记录文件在服务器上的存储位置信息到日志中,方便后续查看和排查问题 logger.info("Server File Location=" + path + avatorName); + // 创建表示文件上传成功的消息对象,并设置相应的成功状态、提示信息、文件路径以及文件所在的域名等信息 UploaderMessage msg = new UploaderMessage(); msg.setStatus(Status.SUCCESS); msg.setStatusMsg("File upload success"); @@ -112,30 +169,38 @@ public class AccountController { msg.setFileDomain(setting.domain); return msg; } catch (Exception e) { + // 如果在文件上传过程中出现异常,创建表示文件上传失败的消息对象,并设置相应的错误状态和提示信息,然后返回该对象告知前端上传失败 UploaderMessage msg = new UploaderMessage(); msg.setStatus(Status.ERROR); msg.setError("File upload file"); return msg; } finally { - if (out != null) { + // 在最终块中确保输出流资源被正确关闭,避免资源泄露 + if (out!= null) { out.close(); out = null; } - if (in != null) { + // 在最终块中确保输入流资源被正确关闭,避免资源泄露 + if (in!= null) { in.close(); in = null; } } } else { + // 如果上传的文件为空,创建表示文件为空的错误消息对象,并设置相应的错误状态和提示信息,然后返回该对象告知前端文件为空 UploaderMessage msg = new UploaderMessage(); msg.setStatus(Status.ERROR); msg.setError("File is empty"); return msg; } } - + /** + * 生成头像编号的方法,先根据当前日期格式化得到年月格式的字符串作为缓存的键前缀,然后通过缓存服务获取自增的编号,再按照指定格式进行格式化,最后拼接前缀生成完整的头像编号 + * + * @return 返回生成的头像编号字符串 + */ private String getAvatorNo() { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); String format = sdf.format(new Date()); @@ -145,4 +210,4 @@ public class AccountController { String avatorNo = AVATOR_PREFIX + df.format(incr); return avatorNo; } -} +} \ No newline at end of file diff --git a/tamguo/src/main/java/com/tamguo/web/member/MemberPaperController.java b/tamguo/src/main/java/com/tamguo/web/member/MemberPaperController.java index 8405e7e..f649278 100644 --- a/tamguo/src/main/java/com/tamguo/web/member/MemberPaperController.java +++ b/tamguo/src/main/java/com/tamguo/web/member/MemberPaperController.java @@ -19,109 +19,182 @@ import com.tamguo.service.IPaperService; import com.tamguo.util.ExceptionSupport; import com.tamguo.util.Result; +// 标识这是一个Spring的控制器类,用于处理Web请求并返回相应的视图或数据 @Controller public class MemberPaperController { - + + // 自动注入IPaperService,用于处理试卷相关的业务逻辑,比如试卷的查询、添加、修改、删除等操作 @Autowired private IPaperService iPaperService; - + /** + * 处理会员试卷页面的GET请求,设置视图名称为"member/paperList",用于返回相应的试卷列表页面视图给用户 + * + * @param model 用于传递数据到视图的ModelAndView对象(此处未添加额外数据) + * @param session 当前的HttpSession对象,可从中获取会话相关的属性(此处未使用到相关属性) + * @return 返回包含视图名称的ModelAndView对象,以便渲染试卷列表页面视图 + */ @RequestMapping(value = "/member/paper", method = RequestMethod.GET) - public ModelAndView paper(ModelAndView model, HttpSession session){ + public ModelAndView paper(ModelAndView model, HttpSession session) { model.setViewName("member/paperList"); return model; } - + + /** + * 处理查找试卷的GET请求,根据传入的试卷ID调用试卷服务查找对应的试卷信息,然后将查找结果包装在表示成功的Result对象中返回 + * + * @param paperId 要查找的试卷的唯一标识符 + * @return 返回包含查找结果的Result对象,如果查找成功则Result对象中包含对应的试卷信息 + */ @RequestMapping(value = "/member/findPaper", method = RequestMethod.GET) @ResponseBody public Result findPaper(String paperId) { return Result.successResult(iPaperService.find(paperId)); } - - @RequestMapping(value = "member/paper/list" , method = RequestMethod.GET) + + /** + * 处理获取试卷列表的GET请求,从会话中获取当前会员信息,根据传入的查询参数(试卷名称、页码、每页数量)构建分页对象,调用试卷服务获取会员对应的试卷列表信息, + * 最后将列表数据按照特定格式包装在Map中返回,以便前端进行展示(可能用于支持类似表格形式展示试卷列表,符合jqGrid等前端组件的数据格式要求) + * + * @param name 试卷名称,用于筛选查找试卷(可为空,表示不按名称筛选) + * @param page 当前页码,用于分页查询 + * @param limit 每页显示的记录数量,用于分页查询 + * @param session 当前的HttpSession对象,从中获取当前会员信息,以确定是哪个会员的试卷列表 + * @return 返回包含试卷列表数据、总记录数、每页数量、当前页码、总页数等信息的Map对象,符合前端展示要求的格式 + */ + @RequestMapping(value = "member/paper/list", method = RequestMethod.GET) @ResponseBody - public Map paperList(String name , Integer page , Integer limit , HttpSession session){ - MemberEntity member = ((MemberEntity)session.getAttribute("currMember")); + public Map paperList(String name, Integer page, Integer limit, HttpSession session) { + MemberEntity member = ((MemberEntity) session.getAttribute("currMember")); Page p = new Page<>(); p.setCurrent(page); p.setSize(limit); - Page list = iPaperService.memberPaperList(name, member.getUid() , p); + Page list = iPaperService.memberPaperList(name, member.getUid(), p); return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages()); } - - @RequestMapping(value="member/paperList/addPaperQuestionInfo",method=RequestMethod.POST) + + /** + * 处理添加试卷问题信息的POST请求,从请求体中的JSON数据中解析出相关参数(试卷ID、标题、类型等),根据类型获取对应的描述信息,然后调用试卷服务添加试卷问题信息, + * 如果操作成功则返回表示成功的Result对象,若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param data 包含试卷问题信息相关参数的JSONObject对象,通过请求体接收 + * @return 返回表示添加操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ + @RequestMapping(value = "member/paperList/addPaperQuestionInfo", method = RequestMethod.POST) @ResponseBody - public Result addPaperQuestionInfo(@RequestBody JSONObject data){ + public Result addPaperQuestionInfo(@RequestBody JSONObject data) { try { - String paperId ; String title ; String name ;String type; + String paperId; + String title; + String name; + String type; paperId = data.getString("uid"); title = data.getString("title"); type = data.getString("type"); name = QuestionType.getQuestionType(type).getDesc(); - iPaperService.addPaperQuestionInfo(paperId , title , name , type); + iPaperService.addPaperQuestionInfo(paperId, title, name, type); return Result.result(0, null, "修改成功"); } catch (Exception e) { return ExceptionSupport.resolverResult("添加questionInfo", this.getClass(), e); } } - + + /** + * 处理更新试卷问题信息的POST请求,从请求体中的JSON数据中解析出相关参数(试卷ID、标题、类型、问题信息唯一标识符等),根据类型获取对应的描述信息, + * 然后调用试卷服务更新试卷问题信息,如果操作成功则返回表示成功的Result对象,若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param data 包含试卷问题信息相关更新参数的JSONObject对象,通过请求体接收 + * @return 返回表示更新操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping("member/paperList/updatePaperQuestionInfo.html") @ResponseBody - public Result updatePaperQuestionInfo(@RequestBody JSONObject data){ + public Result updatePaperQuestionInfo(@RequestBody JSONObject data) { try { - String paperId ; String title ; String name ; String type ; String uid; + String paperId; + String title; + String name; + String type; + String uid; paperId = data.getString("uid"); title = data.getString("title"); type = data.getString("type"); name = QuestionType.getQuestionType(type).getDesc(); uid = data.getString("infoUid"); - iPaperService.updatePaperQuestionInfo(paperId , title , name , type , uid); + iPaperService.updatePaperQuestionInfo(paperId, title, name, type, uid); return Result.result(0, null, "修改成功"); } catch (Exception e) { return ExceptionSupport.resolverResult("修改questionInfo", this.getClass(), e); } } - + + /** + * 处理删除试卷的请求,尝试调用试卷服务删除指定ID的试卷,如果操作成功则返回相应的删除结果(可能是成功的Result对象),若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param paperId 要删除的试卷的唯一标识符 + * @return 返回表示删除操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping("member/paperList/deletePaper") @ResponseBody - public Result deletePaper(String paperId){ + public Result deletePaper(String paperId) { try { return iPaperService.deletePaper(paperId); } catch (Exception e) { return ExceptionSupport.resolverResult("删除试卷", this.getClass(), e); } } - + + /** + * 处理删除试卷问题信息(可能是试卷下的子项相关信息,从名称推测)的请求,尝试调用试卷服务根据试卷ID和问题信息唯一标识符删除对应的信息, + * 如果操作成功则返回相应的删除结果(可能是成功的Result对象),若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param paperId 试卷的唯一标识符,用于定位到对应的试卷 + * @param uid 试卷问题信息的唯一标识符,用于确定要删除的具体子项信息 + * @return 返回表示删除操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping("member/paperList/deletePaperQuestionInfoBtn") @ResponseBody - public Result deletePaperQuestionInfoBtn(String paperId , String uid){ + public Result deletePaperQuestionInfoBtn(String paperId, String uid) { try { - return iPaperService.deletePaperQuestionInfoBtn(paperId , uid); + return iPaperService.deletePaperQuestionInfoBtn(paperId, uid); } catch (Exception e) { return ExceptionSupport.resolverResult("删除子卷", this.getClass(), e); } } - - @RequestMapping(value="member/paperList/addPaper.html",method=RequestMethod.POST) + + /** + * 处理添加试卷的POST请求,从会话中获取当前会员信息并设置为试卷的创建者ID,然后调用试卷服务添加试卷,如果操作成功则返回表示成功的Result对象, + * 若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param paper 包含试卷相关信息的PaperEntity对象,通过请求体接收 + * @param session 当前的HttpSession对象,从中获取当前会员信息,用于设置试卷创建者ID + * @return 返回表示添加操作结果的Result对象,成功时包含添加后的试卷信息及相应提示信息,出现异常时返回异常处理后的结果 + */ + @RequestMapping(value = "member/paperList/addPaper.html", method = RequestMethod.POST) @ResponseBody - public Result addPaper(@RequestBody PaperEntity paper,HttpSession session){ + public Result addPaper(@RequestBody PaperEntity paper, HttpSession session) { try { MemberEntity member = (MemberEntity) session.getAttribute("currMember"); paper.setCreaterId(member.getUid()); iPaperService.addPaper(paper); - return Result.result(Result.SUCCESS_CODE, paper, "添加成功"); + return Result.result(Result.SUCCESS_CODE, paper, "添加成功"); } catch (Exception e) { return ExceptionSupport.resolverResult("添加试卷", this.getClass(), e); } } - - @RequestMapping(value="member/paperList/updatePaper.html",method=RequestMethod.POST) + + /** + * 处理更新试卷的POST请求,尝试调用试卷服务更新传入的试卷信息,如果操作成功则返回相应的更新结果(可能是成功的Result对象),若出现异常则通过异常处理工具类返回相应的异常结果 + * + * @param paper 包含要更新的试卷相关信息的PaperEntity对象,通过请求体接收 + * @return 返回表示更新操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ + @RequestMapping(value = "member/paperList/updatePaper.html", method = RequestMethod.POST) @ResponseBody - public Result updatePaper(@RequestBody PaperEntity paper){ + public Result updatePaper(@RequestBody PaperEntity paper) { try { return iPaperService.updatePaper(paper); } catch (Exception e) { return ExceptionSupport.resolverResult("修改试卷", this.getClass(), e); } } -} +} \ No newline at end of file diff --git a/tamguo/src/main/java/com/tamguo/web/member/QuestionController.java b/tamguo/src/main/java/com/tamguo/web/member/QuestionController.java index 07f4237..de04275 100644 --- a/tamguo/src/main/java/com/tamguo/web/member/QuestionController.java +++ b/tamguo/src/main/java/com/tamguo/web/member/QuestionController.java @@ -17,80 +17,146 @@ import com.tamguo.service.IQuestionService; import com.tamguo.util.ExceptionSupport; import com.tamguo.util.Result; -@Controller(value="memberQuestionController") +// 标识这是一个Spring的控制器类,名为"memberQuestionController",用于处理与会员相关的试题操作的Web请求,并返回相应的视图或数据 +@Controller(value = "memberQuestionController") public class QuestionController { - + + // 自动注入IQuestionService,用于处理试题相关的业务逻辑,例如试题的添加、查询、更新、删除等操作 @Autowired private IQuestionService iQuestionService; + + // 自动注入IPaperService,用于获取试卷相关信息,可能在试题与试卷关联等操作中会用到 @Autowired private IPaperService iPaperService; - + + /** + * 处理添加试题页面的GET请求,根据传入的试卷ID,通过试卷服务获取对应的试卷信息,设置视图名称为"member/addQuestion", + * 并将试卷信息添加到模型中,最后返回包含视图名称和试卷信息的ModelAndView对象,以便渲染相应的添加试题页面视图给用户 + * + * @param paperId 要添加试题所属的试卷的唯一标识符,用于查找对应的试卷信息 + * @param model 用于传递数据到视图的ModelAndView对象,在这里将试卷信息添加到该对象中 + * @return 返回包含视图名称和试卷信息的ModelAndView对象,用于渲染添加试题页面视图 + */ @RequestMapping(value = "/member/addQuestion", method = RequestMethod.GET) - public ModelAndView index(String paperId , ModelAndView model){ + public ModelAndView index(String paperId, ModelAndView model) { model.setViewName("member/addQuestion"); model.addObject("paper", iPaperService.find(paperId)); return model; } - + + /** + * 处理提交试题的POST请求,尝试调用试题服务添加传入的试题信息,如果操作成功则返回相应的添加结果(可能是成功的Result对象), + * 若出现异常则通过异常处理工具类返回相应的异常结果,告知前端添加试题操作出现问题 + * + * @param question 包含要添加的试题相关信息的QuestionEntity对象,通过请求参数接收 + * @return 返回表示添加试题操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping(value = "/member/submitQuestion", method = RequestMethod.POST) @ResponseBody - public Result submitQuestion(QuestionEntity question){ + public Result submitQuestion(QuestionEntity question) { try { return iQuestionService.addQuestion(question); } catch (Exception e) { return ExceptionSupport.resolverResult("添加试题", this.getClass(), e); } } - + + /** + * 处理试题列表页面的GET请求,根据传入的试卷ID,通过试卷服务获取对应的试卷信息,将试卷信息添加到模型中,设置视图名称为"member/questionList", + * 最后返回包含视图名称和试卷信息的ModelAndView对象,以便渲染相应的试题列表页面视图给用户 + * + * @param paperId 要展示其试题列表的试卷的唯一标识符,用于查找对应的试卷信息 + * @param model 用于传递数据到视图的ModelAndView对象,在这里将试卷信息添加到该对象中 + * @return 返回包含视图名称和试卷信息的ModelAndView对象,用于渲染试题列表页面视图 + */ @RequestMapping(value = "/member/questionList", method = RequestMethod.GET) - public ModelAndView questionList(String paperId , ModelAndView model){ + public ModelAndView questionList(String paperId, ModelAndView model) { model.addObject("paper", iPaperService.find(paperId)); model.setViewName("member/questionList"); return model; } - - @RequestMapping(value = "/member/queryQuestionList" , method=RequestMethod.POST) + + /** + * 处理查询试题列表的POST请求,从请求体中的JSON数据中解析出查询相关的参数(试题类型、唯一标识符、内容、所属试卷ID、页码、每页数量等), + * 根据这些参数构建分页对象并调用试题服务查询符合条件的试题列表信息,最后将列表数据按照特定格式包装在Map中返回,以便前端进行展示(可能用于支持类似表格形式展示试题列表,符合jqGrid等前端组件的数据格式要求) + * + * @param data 包含试题查询相关参数的JSONObject对象,通过请求体接收 + * @return 返回包含试题列表数据、总记录数、每页数量、当前页码、总页数等信息的Map对象,符合前端展示要求的格式 + */ + @RequestMapping(value = "/member/queryQuestionList", method = RequestMethod.POST) @ResponseBody - public Map queryQuestionList(@RequestBody JSONObject data){ - String questionType ; String uid ; String content ; String paperId ; - Integer page ; Integer limit; + public Map queryQuestionList(@RequestBody JSONObject data) { + String questionType; + String uid; + String content; + String paperId; + Integer page; + Integer limit; questionType = data.getString("questionType"); uid = data.getString("uid"); - content = data.getString("content"); + content = data.getString("questionContent"); paperId = data.getString("paperId"); page = data.getInteger("page"); limit = data.getInteger("limit"); Page p = new Page<>(); p.setCurrent(page); p.setSize(limit); - Page list = iQuestionService.queryQuestionList(questionType , uid , content , paperId , p); + Page list = iQuestionService.queryQuestionList(questionType, uid, content, paperId, p); return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages()); } - + + /** + * 处理编辑试题页面的GET请求,根据传入的试卷ID和试题ID,通过试卷服务获取对应的试卷信息,设置视图名称为"member/editQuestion", + * 并将试卷信息以及试题ID添加到模型中,最后返回包含视图名称、试卷信息和试题ID的ModelAndView对象,以便渲染相应的编辑试题页面视图给用户 + * + * @param paperId 要编辑的试题所属的试卷的唯一标识符,用于查找对应的试卷信息 + * @param questionId 要编辑的试题的唯一标识符,用于在编辑页面定位到具体的试题 + * @param model 用于传递数据到视图的ModelAndView对象,在这里将试卷信息和试题ID添加到该对象中 + * @return 返回包含视图名称、试卷信息和试题ID的ModelAndView对象,用于渲染编辑试题页面视图 + */ @RequestMapping(value = "/member/editQuestion", method = RequestMethod.GET) - public ModelAndView editQuestion(String paperId , String questionId , ModelAndView model){ + public ModelAndView editQuestion(String paperId, String questionId, ModelAndView model) { model.setViewName("member/editQuestion"); model.addObject("paper", iPaperService.find(paperId)); - model.addObject("questionId" , questionId); + model.addObject("questionId", questionId); return model; } - + + /** + * 处理获取试题信息的GET请求,根据传入的试题ID调用试题服务查找对应的试题信息,然后将查找结果包装在表示成功的Result对象中返回 + * + * @param questionId 要获取信息的试题的唯一标识符 + * @return 返回包含查找结果的Result对象,如果查找成功则Result对象中包含对应的试题信息 + */ @RequestMapping(value = "/member/getQuestion", method = RequestMethod.GET) @ResponseBody public Result getQuestion(String questionId) { return Result.successResult(iQuestionService.select(questionId)); } - + + /** + * 处理更新试题的POST请求,尝试调用试题服务更新传入的试题信息,如果操作成功则返回相应的更新结果(可能是成功的Result对象), + * 若出现异常则通过异常处理工具类返回相应的异常结果,告知前端更新试题操作出现问题 + * + * @param question 包含要更新的试题相关信息的QuestionEntity对象,通过请求参数接收 + * @return 返回表示更新试题操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping(value = "/member/updateQuestion", method = RequestMethod.POST) @ResponseBody public Result updateQuestion(QuestionEntity question) { return iQuestionService.updateQuestion(question); } - - + + /** + * 处理删除试题的GET请求,尝试调用试题服务根据传入的试题唯一标识符删除对应的试题,如果操作成功则返回相应的删除结果(可能是成功的Result对象), + * 若出现异常则通过异常处理工具类返回相应的异常结果,告知前端删除试题操作出现问题 + * + * @param uid 要删除的试题的唯一标识符,用于定位到具体要删除的试题 + * @return 返回表示删除试题操作结果的Result对象,成功时包含相应提示信息,出现异常时返回异常处理后的结果 + */ @RequestMapping(value = "/member/deleteQuestion", method = RequestMethod.GET) @ResponseBody public Result deleteQuestion(@RequestBody String uid) { return iQuestionService.delete(uid); } -} +} \ No newline at end of file