diff --git a/src/main/java/com/controller/ConfigController.java b/src/main/java/com/controller/ConfigController.java index 180cbc5..f502763 100644 --- a/src/main/java/com/controller/ConfigController.java +++ b/src/main/java/com/controller/ConfigController.java @@ -1,7 +1,5 @@ - package com.controller; - import java.util.Arrays; import java.util.Map; @@ -13,100 +11,118 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.annotation.IgnoreAuth; -import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.entity.ConfigEntity; -import com.service.ConfigService; -import com.utils.MPUtil; +import com.annotation.IgnoreAuth; +import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis-Plus的实体包装器 +import com.entity.ConfigEntity; // 配置实体类 +import com.service.ConfigService; // 配置服务类 +import com.utils.MPUtil; // MyBatis-Plus工具类 import com.utils.PageUtils; import com.utils.R; -import com.utils.ValidatorUtils; +import com.utils.ValidatorUtils; /** * 登录相关 */ -@RequestMapping("config") -@RestController -public class ConfigController{ - - @Autowired - private ConfigService configService; +@RequestMapping("config") // 设置基本请求路径为"/config" +@RestController // 标记为REST风格的控制器 +public class ConfigController { + + @Autowired // 自动注入ConfigService + private ConfigService configService; - /** + /** * 列表 + * @param params 查询参数 + * @param config 配置信息 + * @return 分页后的配置信息 */ @RequestMapping("/page") - public R page(@RequestParam Map params,ConfigEntity config){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); - return R.ok().put("data", page); + public R page(@RequestParam Map params, ConfigEntity config) { + EntityWrapper ew = new EntityWrapper(); // 创建EntityWrapper用于条件构造 + PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据 + return R.ok().put("data", page); } - /** + /** * 列表 + * @param params 查询参数 + * @param config 配置信息 + * @return 所有配置信息的列表 */ - @IgnoreAuth + @IgnoreAuth // 忽略身份验证 @RequestMapping("/list") - public R list(@RequestParam Map params,ConfigEntity config){ - EntityWrapper ew = new EntityWrapper(); - PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); - return R.ok().put("data", page); + public R list(@RequestParam Map params, ConfigEntity config) { + EntityWrapper ew = new EntityWrapper(); // 创建EntityWrapper用于条件构造 + PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据 + return R.ok().put("data", page); } /** * 信息 + * @param id 配置ID + * @return 指定ID的配置信息 */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") String id){ - ConfigEntity config = configService.selectById(id); + @RequestMapping("/info/{id}") // 用于获取指定ID的配置信息 + public R info(@PathVariable("id") String id) { + ConfigEntity config = configService.selectById(id); // 根据ID查询配置 return R.ok().put("data", config); } /** * 详情 + * @param id 配置ID + * @return 指定ID的配置信息,忽略身份验证 */ - @IgnoreAuth - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") String id){ - ConfigEntity config = configService.selectById(id); + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/detail/{id}") // 用于获取指定ID的配置信息详情 + public R detail(@PathVariable("id") String id) { + ConfigEntity config = configService.selectById(id); // 根据ID查询配置 return R.ok().put("data", config); } /** * 根据name获取信息 + * @param name 配置名称 + * @return 指定名称的配置信息 */ - @RequestMapping("/info") - public R infoByName(@RequestParam String name){ - ConfigEntity config = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); - return R.ok().put("data", config); + @RequestMapping("/info") // 用于根据名称获取配置信息 + public R infoByName(@RequestParam String name) { + ConfigEntity config = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); // 根据名称查询配置 + return R.ok().put("data", config); } /** * 保存 + * @param config 配置信息 + * @return 保存结果 */ - @PostMapping("/save") - public R save(@RequestBody ConfigEntity config){ -// ValidatorUtils.validateEntity(config); - configService.insert(config); + @PostMapping("/save") // 用于保存配置 + public R save(@RequestBody ConfigEntity config) { + // ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用) + configService.insert(config); // 保存配置 return R.ok(); } /** * 修改 + * @param config 配置信息 + * @return 修改结果 */ - @RequestMapping("/update") - public R update(@RequestBody ConfigEntity config){ -// ValidatorUtils.validateEntity(config); - configService.updateById(config);//全部更新 - return R.ok(); + @RequestMapping("/update") // 用于修改配置 + public R update(@RequestBody ConfigEntity config) { + // ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用) + configService.updateById(config); // 根据ID更新配置 + return R.ok(); } /** * 删除 + * @param ids 配置ID数组 + * @return 删除结果 */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - configService.deleteBatchIds(Arrays.asList(ids)); + @RequestMapping("/delete") // 用于删除配置 + public R delete(@RequestBody Long[] ids) { + configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除配置 return R.ok(); } } diff --git a/src/main/java/com/controller/FileController.java b/src/main/java/com/controller/FileController.java index bf53f29..34e4bb9 100644 --- a/src/main/java/com/controller/FileController.java +++ b/src/main/java/com/controller/FileController.java @@ -7,84 +7,103 @@ import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的依赖注入注解 +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; // 导入Spring的REST控制器注解 +import org.springframework.web.multipart.MultipartFile; // 导入Spring的文件上传接口 -import com.annotation.IgnoreAuth; -import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.entity.ConfigEntity; -import com.entity.EIException; -import com.service.ConfigService; -import com.utils.R; +import com.annotation.IgnoreAuth; // 导入自定义注解,表示忽略身份验证 +import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper,用于构建查询条件 +import com.entity.ConfigEntity; +import com.entity.EIException; +import com.service.ConfigService; +import com.utils.R; /** * 上传文件映射表 */ -@RestController -@RequestMapping("file") -@SuppressWarnings({"unchecked","rawtypes"}) -public class FileController{ - @Autowired +@RestController // 标记该类为REST控制器 +@RequestMapping("file") // 设置基本请求路径为"/file" +@SuppressWarnings({"unchecked","rawtypes"}) // 忽略编译警告 +public class FileController { + + @Autowired // 自动注入ConfigService服务 private ConfigService configService; - /** - * 上传文件 - */ - @RequestMapping("/upload") - @IgnoreAuth - public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception { - if (file.isEmpty()) { - throw new EIException("上传文件不能为空"); - } - String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1); - String fileName = new Date().getTime()+"."+fileExt; - File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName); - file.transferTo(dest); - /** - * 如果使用idea或者eclipse重启项目,发现之前上传的图片或者文件丢失,将下面一行代码注释打开 - * 请将以下的"D:\\ssmpiv99\\src\\main\\webapp\\upload"替换成你本地项目的upload路径, - * 并且项目路径不能存在中文、空格等特殊字符 - */ - //FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/ - if(StringUtils.isNotBlank(type) && type.equals("1")) { - ConfigEntity configEntity = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); - if(configEntity==null) { - configEntity = new ConfigEntity(); - configEntity.setName("faceFile"); - configEntity.setValue(fileName); - } else { - configEntity.setValue(fileName); - } - configService.insertOrUpdate(configEntity); - } - return R.ok().put("file", fileName); - } - - /** - * 下载文件 - */ - @IgnoreAuth - @RequestMapping("/download") - public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) { - try { - File file = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName); - if (file.exists()) { - response.reset(); - response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+"\""); - response.setHeader("Cache-Control", "no-cache"); - response.setHeader("Access-Control-Allow-Credentials", "true"); - response.setContentType("application/octet-stream; charset=UTF-8"); - IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - + /** + * 上传文件 + * @param file 上传的文件 + * @param type 文件类型标识 + * @param request HttpServletRequest对象 + * @return 上传结果 + */ + @RequestMapping("/upload") // 映射请求路径为"/upload" + @IgnoreAuth // 忽略身份验证 + public R upload(@RequestParam("file") MultipartFile file, String type, HttpServletRequest request) throws Exception { + // 检查上传的文件是否为空 + if (file.isEmpty()) { + throw new EIException("上传文件不能为空"); + } + // 获取文件扩展名 + String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); + String fileName = new Date().getTime() + "." + fileExt; + // 定义文件保存的目标路径 + File dest = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + fileName); + file.transferTo(dest); + + /** + * 如果使用IDEA或者Eclipse重启项目后发现之前上传的文件丢失, + * 请将下面一行代码注释打开 + * 并将"D:\\ssmpiv99\\src\\main\\webapp\\upload"替换为你本地项目的upload路径, + * 确保项目路径中不存在中文、空格等特殊字符 + */ + // FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload" + "/" + fileName)); /** 修改了路径后请将该行最前面的//注释去掉 **/ + + // 如果type不为空且等于"1",则更新或保存配置信息 + if (StringUtils.isNotBlank(type) && type.equals("1")) { + ConfigEntity configEntity = configService.selectOne(new EntityWrapper().eq("name", "faceFile")); + if (configEntity == null) { + configEntity = new ConfigEntity(); // 创建新的配置实体 + configEntity.setName("faceFile"); + configEntity.setValue(fileName); + } else { + configEntity.setValue(fileName); + } + configService.insertOrUpdate(configEntity); // 保存或更新配置 + } + return R.ok().put("file", fileName); // 返回上传结果,包含文件名 + } + + /** + * 下载文件 + * @param fileName 文件名 + * @param request HttpServletRequest对象 + * @param response HttpServletResponse对象 + */ + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/download") // 映射请求路径为"/download" + public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) { + try { + // 定义文件的完整路径 + File file = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + fileName); + // 检查文件是否存在 + if (file.exists()) { + response.reset(); // 重置响应 + // 设置响应头,指示文件下载 + response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Access-Control-Allow-Credentials", "true"); + response.setContentType("application/octet-stream; charset=UTF-8"); // 设置内容类型 + // 将文件内容写入响应输出流 + IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream()); + } + + } catch (IOException e) { + e.printStackTrace(); // 打印异常信息 + } + } } diff --git a/src/main/java/com/controller/ForumController.java b/src/main/java/com/controller/ForumController.java index 270bb00..e885522 100644 --- a/src/main/java/com/controller/ForumController.java +++ b/src/main/java/com/controller/ForumController.java @@ -1,42 +1,42 @@ package com.controller; -import java.math.BigDecimal; +import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Map; +import java.text.ParseException; // 导入解析异常 +import java.util.ArrayList; +import java.util.Arrays; // 导入Arrays工具类 +import java.util.Calendar; +import java.util.Map; // 导入Map接口 import java.util.HashMap; -import java.util.Iterator; -import java.util.Date; -import java.util.List; -import javax.servlet.http.HttpServletRequest; +import java.util.Iterator; // 导入迭代器接口 +import java.util.Date; +import java.util.List; +import javax.servlet.http.HttpServletRequest; // 导入Servlet请求类 import java.io.IOException; -import com.utils.ValidatorUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; +import com.utils.ValidatorUtils; // 导入验证工具类 +import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang的StringUtils类,用于字符串操作 +import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的依赖注入注解 import org.springframework.transaction.annotation.Transactional; -import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.PathVariable; // 导入路径变量注解 +import org.springframework.web.bind.annotation.RequestBody; // 导入请求体注解 +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import com.baomidou.mybatisplus.mapper.EntityWrapper; +import org.springframework.web.bind.annotation.RestController; // 导入REST控制器注解 +import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; -import com.annotation.IgnoreAuth; +import com.annotation.IgnoreAuth; -import com.entity.ForumEntity; -import com.entity.view.ForumView; +import com.entity.ForumEntity; // 导入论坛实体类 +import com.entity.view.ForumView; // 导入论坛视图类 -import com.service.ForumService; +import com.service.ForumService; // 导入论坛服务类 import com.service.TokenService; -import com.utils.PageUtils; +import com.utils.PageUtils; // 导入分页工具类 import com.utils.R; import com.utils.MD5Util; -import com.utils.MPUtil; +import com.utils.MPUtil; // 导入MyBatis-Plus工具类 import com.utils.CommonUtil; /** @@ -46,217 +46,238 @@ import com.utils.CommonUtil; * @email * @date 2023-02-21 09:46:06 */ -@RestController +@RestController // 标记该类为REST控制器 @RequestMapping("/forum") public class ForumController { @Autowired - private ForumService forumService; - - - - - + private ForumService forumService; // 注入论坛服务 /** * 后端列表 + * @param params 请求参数 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 论坛列表分页数据 */ - @RequestMapping("/page") - public R page(@RequestParam Map params,ForumEntity forum, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - forum.setUserid((Long)request.getSession().getAttribute("userId")); - } + @RequestMapping("/page") // 映射请求路径为"/page" + public R page(@RequestParam Map params, ForumEntity forum, HttpServletRequest request) { + // 如果当前用户不是管理员,则设置用户ID + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + forum.setUserid((Long) request.getSession().getAttribute("userId")); + } EntityWrapper ew = new EntityWrapper(); - - PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); + // 查询论坛列表分页数据 + PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); + request.setAttribute("data", page); // 将数据设置到请求属性中 + return R.ok().put("data", page); } /** * 前端列表 + * @param params 请求参数 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 论坛列表分页数据 */ - @RequestMapping("/list") - public R list(@RequestParam Map params,ForumEntity forum, - HttpServletRequest request){ - if(!request.getSession().getAttribute("role").toString().equals("管理员")) { - forum.setUserid((Long)request.getSession().getAttribute("userId")); - } + @RequestMapping("/list") // 映射请求路径为"/list" + public R list(@RequestParam Map params, ForumEntity forum, HttpServletRequest request) { + // 如果当前用户不是管理员,则设置用户ID + if (!request.getSession().getAttribute("role").toString().equals("管理员")) { + forum.setUserid((Long) request.getSession().getAttribute("userId")); + } EntityWrapper ew = new EntityWrapper(); - - PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); + // 查询论坛列表分页数据 + PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); + request.setAttribute("data", page); // 将数据设置到请求属性中 + return R.ok().put("data", page); } - /** - * 列表 + /** + * 允许匿名访问的列表 + * @param params 请求参数 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 论坛列表分页数据 */ - @IgnoreAuth - @RequestMapping("/flist") - public R flist(@RequestParam Map params,ForumEntity forum, HttpServletRequest request){ + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/flist") // 映射请求路径为"/flist" + public R flist(@RequestParam Map params, ForumEntity forum, HttpServletRequest request) { EntityWrapper ew = new EntityWrapper(); - PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); - return R.ok().put("data", page); + // 查询论坛列表分页数据 + PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); + return R.ok().put("data", page); } - /** - * 查询 + /** + * 查询论坛信息 + * @param forum 论坛实体 + * @return 论坛信息 */ - @RequestMapping("/query") - public R query(ForumEntity forum){ - EntityWrapper< ForumEntity> ew = new EntityWrapper< ForumEntity>(); - ew.allEq(MPUtil.allEQMapPre( forum, "forum")); - ForumView forumView = forumService.selectView(ew); - return R.ok("查询论坛表成功").put("data", forumView); + @RequestMapping("/query") // 映射请求路径为"/query" + public R query(ForumEntity forum) { + EntityWrapper ew = new EntityWrapper(); + ew.allEq(MPUtil.allEQMapPre(forum, "forum")); // 构建查询条件 + ForumView forumView = forumService.selectView(ew); // 查询论坛视图 + return R.ok("查询论坛表成功").put("data", forumView); } /** - * 后端详情 + * 获取后端论坛详情 + * @param id 论坛ID + * @return 论坛信息 */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - ForumEntity forum = forumService.selectById(id); + @RequestMapping("/info/{id}") // 映射请求路径为"/info/{id}" + public R info(@PathVariable("id") Long id) { + ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛 return R.ok().put("data", forum); } /** - * 前端详情 + * 获取前端论坛详情 + * @param id 论坛ID + * @return 论坛信息 */ - @IgnoreAuth - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - ForumEntity forum = forumService.selectById(id); - return R.ok().put("data", forum); + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/detail/{id}") // 映射请求路径为"/detail/{id}" + public R detail(@PathVariable("id") Long id) { + ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛 + return R.ok().put("data", forum); } - /** - * 论坛详情 + /** + * 获取论坛及其子项 + * @param id 论坛ID + * @return 论坛信息及子项 */ - @IgnoreAuth - @RequestMapping("/list/{id}") - public R list(@PathVariable("id") String id){ - ForumEntity forum = forumService.selectById(id); - getChilds(forum); - return R.ok().put("data", forum); + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/list/{id}") // 映射请求路径为"/list/{id}" + public R list(@PathVariable("id") String id) { + ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛 + getChilds(forum); // 获取子项 + return R.ok().put("data", forum); // 返回论坛信息及子项 } - private ForumEntity getChilds(ForumEntity forum) { - List childs = new ArrayList(); - childs = forumService.selectList(new EntityWrapper().eq("parentid", forum.getId())); - if(childs == null || childs.size()==0) { - return null; - } - forum.setChilds(childs); - for(ForumEntity forumEntity : childs) { - getChilds(forumEntity); - } - return forum; + /** + * 递归获取子项 + * @param forum 论坛实体 + * @return 具有子项的论坛 + */ + private ForumEntity getChilds(ForumEntity forum) { + List childs = new ArrayList(); + childs = forumService.selectList(new EntityWrapper().eq("parentid", forum.getId())); // 根据父ID查询子项 + if (childs == null || childs.size() == 0) { + return null; // 如果没有子项,则返回null + } + forum.setChilds(childs); // 设置子项 + for (ForumEntity forumEntity : childs) { + getChilds(forumEntity); // 递归获取每个子项的子项 + } + return forum; // 返回具有子项的论坛 } - - /** - * 后端保存 + * 后端保存论坛信息 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 保存结果 */ - @RequestMapping("/save") - public R save(@RequestBody ForumEntity forum, HttpServletRequest request){ - forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(forum); - forum.setUserid((Long)request.getSession().getAttribute("userId")); - - forumService.insert(forum); + @RequestMapping("/save") // 映射请求路径为"/save" + public R save(@RequestBody ForumEntity forum, HttpServletRequest request) { + forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用) + forum.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + forumService.insert(forum); // 保存论坛信息 return R.ok(); } /** - * 前端保存 + * 前端保存论坛信息 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 保存结果 */ - @RequestMapping("/add") - public R add(@RequestBody ForumEntity forum, HttpServletRequest request){ - forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(forum); - forum.setUserid((Long)request.getSession().getAttribute("userId")); - - forumService.insert(forum); - return R.ok(); + @RequestMapping("/add") // 映射请求路径为"/add" + public R add(@RequestBody ForumEntity forum, HttpServletRequest request) { + forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用) + forum.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID + forumService.insert(forum); // 保存论坛信息 + return R.ok(); } - /** - * 修改 + * 修改论坛信息 + * @param forum 论坛实体 + * @param request HttpServletRequest对象 + * @return 修改结果 */ - @RequestMapping("/update") - @Transactional - public R update(@RequestBody ForumEntity forum, HttpServletRequest request){ - //ValidatorUtils.validateEntity(forum); - forumService.updateById(forum);//全部更新 + @RequestMapping("/update") // 映射请求路径为"/update" + @Transactional // 开启事务 + public R update(@RequestBody ForumEntity forum, HttpServletRequest request) { + // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用) + forumService.updateById(forum); // 更新论坛信息 return R.ok(); } - - /** - * 删除 + * 删除论坛 + * @param ids 论坛ID数组 + * @return 删除结果 */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - forumService.deleteBatchIds(Arrays.asList(ids)); + @RequestMapping("/delete") // 映射请求路径为"/delete" + public R delete(@RequestBody Long[] ids) { + forumService.deleteBatchIds(Arrays.asList(ids)); // 批量删除论坛 return R.ok(); } /** * 提醒接口 + * @param columnName 列名 + * @param type 类型 + * @param map 查询参数 + * @param request HttpServletRequest对象 + * @return 提醒数量 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = forumService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") // 映射请求路径为"/remind/{columnName}/{type}" + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 将列名放入请求参数 + map.put("type", type); // 将类型放入请求参数 + + // 如果类型为2,进行日期提醒处理 + if (type.equals("2")) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar c = Calendar.getInstance(); + Date remindStartDate = null; + Date remindEndDate = null; + if (map.get("remindstart") != null) { + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); + c.setTime(new Date()); + c.add(Calendar.DAY_OF_MONTH, remindStart); // 加上提醒天数 + remindStartDate = c.getTime(); + map.put("remindstart", sdf.format(remindStartDate)); // 格式化日期并放入请求参数 + } + if (map.get("remindend") != null) { + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); + c.setTime(new Date()); + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 加上提醒天数 + remindEndDate = c.getTime(); + map.put("remindend", sdf.format(remindEndDate)); // 格式化日期并放入请求参数 + } + } + + // 构建查询条件 + Wrapper wrapper = new EntityWrapper(); + if (map.get("remindstart") != null) { + wrapper.ge(columnName, map.get("remindstart")); // 大于等于开始日期 + } + if (map.get("remindend") != null) { + wrapper.le(columnName, map.get("remindend")); // 小于等于结束日期 + } + + int count = forumService.selectCount(wrapper); // 查询数量 + return R.ok().put("count", count); // 返回数量 + } } diff --git a/src/main/java/com/controller/LeixingController.java b/src/main/java/com/controller/LeixingController.java index c9fbb33..d33f496 100644 --- a/src/main/java/com/controller/LeixingController.java +++ b/src/main/java/com/controller/LeixingController.java @@ -1,43 +1,43 @@ package com.controller; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; +import java.math.BigDecimal; // 导入BigDecimal以处理高精度数值 +import java.text.SimpleDateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; import java.util.Map; import java.util.HashMap; -import java.util.Iterator; +import java.util.Iterator; // 导入迭代器接口 import java.util.Date; -import java.util.List; -import javax.servlet.http.HttpServletRequest; +import java.util.List; // 导入List接口 +import javax.servlet.http.HttpServletRequest; import java.io.IOException; -import com.utils.ValidatorUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.format.annotation.DateTimeFormat; +import com.utils.ValidatorUtils; +import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang的字符串处理类 +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; // 导入请求参数注解 import org.springframework.web.bind.annotation.RestController; -import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.baomidou.mybatisplus.mapper.Wrapper; -import com.annotation.IgnoreAuth; +import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper,用于构建查询条件 +import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis-Plus的Wrapper接口 +import com.annotation.IgnoreAuth; -import com.entity.LeixingEntity; -import com.entity.view.LeixingView; +import com.entity.LeixingEntity; +import com.entity.view.LeixingView; // 导入类型视图类 -import com.service.LeixingService; -import com.service.TokenService; -import com.utils.PageUtils; -import com.utils.R; +import com.service.LeixingService; // 导入类型服务类 +import com.service.TokenService; +import com.utils.PageUtils; // 导入分页工具类 +import com.utils.R; // 导入响应工具类 import com.utils.MD5Util; -import com.utils.MPUtil; -import com.utils.CommonUtil; +import com.utils.MPUtil; // 导入MyBatis-Plus工具类 +import com.utils.CommonUtil; /** * 类型 @@ -46,185 +46,201 @@ import com.utils.CommonUtil; * @email * @date 2023-02-21 09:46:06 */ -@RestController -@RequestMapping("/leixing") +@RestController // 标记该类为REST控制器 +@RequestMapping("/leixing") // 设置基本请求路径为"/leixing" public class LeixingController { @Autowired - private LeixingService leixingService; - - - - - + private LeixingService leixingService; // 自动注入类型服务 /** * 后端列表 + * @param params 请求参数 + * @param leixing 类型实体 + * @param request HttpServletRequest对象 + * @return 列表数据 */ - @RequestMapping("/page") - public R page(@RequestParam Map params,LeixingEntity leixing, - HttpServletRequest request){ + @RequestMapping("/page") // 映射请求路径为"/page" + public R page(@RequestParam Map params, LeixingEntity leixing, + HttpServletRequest request) { - EntityWrapper ew = new EntityWrapper(); + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 - PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); + // 查询分页数据 + PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); + request.setAttribute("data", page); // 将数据设置到请求属性中 + return R.ok().put("data", page); } /** * 前端列表 + * @param params 请求参数 + * @param leixing 类型实体 + * @param request HttpServletRequest对象 + * @return 列表数据 */ - @IgnoreAuth - @RequestMapping("/list") - public R list(@RequestParam Map params,LeixingEntity leixing, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - - PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/list") // 映射请求路径为"/list" + public R list(@RequestParam Map params, LeixingEntity leixing, + HttpServletRequest request) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + + // 查询分页数据 + PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); + request.setAttribute("data", page); // 将数据设置到请求属性中 + return R.ok().put("data", page); } - /** - * 列表 + /** + * 查询所有列表 + * @param leixing 类型实体 + * @return 查询结果 */ - @RequestMapping("/lists") - public R list( LeixingEntity leixing){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( leixing, "leixing")); + @RequestMapping("/lists") // 映射请求路径为"/lists" + public R list(LeixingEntity leixing) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件 return R.ok().put("data", leixingService.selectListView(ew)); } - /** - * 查询 + /** + * 查询具体信息 + * @param leixing 类型实体 + * @return 查询结果 */ - @RequestMapping("/query") - public R query(LeixingEntity leixing){ - EntityWrapper< LeixingEntity> ew = new EntityWrapper< LeixingEntity>(); - ew.allEq(MPUtil.allEQMapPre( leixing, "leixing")); - LeixingView leixingView = leixingService.selectView(ew); - return R.ok("查询类型成功").put("data", leixingView); + @RequestMapping("/query") // 映射请求路径为"/query" + public R query(LeixingEntity leixing) { + EntityWrapper ew = new EntityWrapper(); // 创建查询条件 + ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件 + LeixingView leixingView = leixingService.selectView(ew); // 查询类型视图 + return R.ok("查询类型成功").put("data", leixingView); } /** - * 后端详情 + * 获取后端详情 + * @param id 类型ID + * @return 类型信息 */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - LeixingEntity leixing = leixingService.selectById(id); + @RequestMapping("/info/{id}") // 映射请求路径为"/info/{id}" + public R info(@PathVariable("id") Long id) { + LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型 return R.ok().put("data", leixing); } /** - * 前端详情 + * 获取前端详情 + * @param id 类型ID + * @return 类型信息 */ - @IgnoreAuth - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - LeixingEntity leixing = leixingService.selectById(id); - return R.ok().put("data", leixing); + @IgnoreAuth // 忽略身份验证 + @RequestMapping("/detail/{id}") // 映射请求路径为"/detail/{id}" + public R detail(@PathVariable("id") Long id) { + LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型 + return R.ok().put("data", leixing); } - - - /** - * 后端保存 + * 后端保存类型信息 + * @param leixing 类型实体 + * @param request HttpServletRequest对象 + * @return 保存结果 */ - @RequestMapping("/save") - public R save(@RequestBody LeixingEntity leixing, HttpServletRequest request){ - leixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(leixing); + @RequestMapping("/save") // 映射请求路径为"/save" + public R save(@RequestBody LeixingEntity leixing, HttpServletRequest request) { + leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用) - leixingService.insert(leixing); - return R.ok(); + leixingService.insert(leixing); // 保存类型信息 + return R.ok(); } /** - * 前端保存 + * 前端保存类型信息 + * @param leixing 类型实体 + * @param request HttpServletRequest对象 + * @return 保存结果 */ - @RequestMapping("/add") - public R add(@RequestBody LeixingEntity leixing, HttpServletRequest request){ - leixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(leixing); + @RequestMapping("/add") // 映射请求路径为"/add" + public R add(@RequestBody LeixingEntity leixing, HttpServletRequest request) { + leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID + // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用) - leixingService.insert(leixing); - return R.ok(); + leixingService.insert(leixing); // 保存类型信息 + return R.ok(); } - /** - * 修改 + * 修改类型信息 + * @param leixing 类型实体 + * @param request HttpServletRequest对象 + * @return 修改结果 */ - @RequestMapping("/update") - @Transactional - public R update(@RequestBody LeixingEntity leixing, HttpServletRequest request){ - //ValidatorUtils.validateEntity(leixing); - leixingService.updateById(leixing);//全部更新 - return R.ok(); + @RequestMapping("/update") // 映射请求路径为"/update" + @Transactional // 开启事务 + public R update(@RequestBody LeixingEntity leixing, HttpServletRequest request) { + // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用) + leixingService.updateById(leixing); // 更新类型信息 + return R.ok(); } - - /** - * 删除 + * 删除类型 + * @param ids 类型ID数组 + * @return 删除结果 */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - leixingService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); + @RequestMapping("/delete") // 映射请求路径为"/delete" + public R delete(@RequestBody Long[] ids) { + leixingService.deleteBatchIds(Arrays.asList(ids)); // 批量删除类型 + return R.ok(); } /** * 提醒接口 + * @param columnName 列名 + * @param type 类型 + * @param map 查询参数 + * @param request HttpServletRequest对象 + * @return 提醒数量 */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = leixingService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - - - - - - - - + @RequestMapping("/remind/{columnName}/{type}") // 映射请求路径为"/remind/{columnName}/{type}" + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + map.put("column", columnName); // 将列名放入请求参数 + map.put("type", type); // 将类型放入请求参数 + + // 如果类型为2,进行日期提醒处理 + if (type.equals("2")) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar c = Calendar.getInstance(); + Date remindStartDate = null; + Date remindEndDate = null; + // 处理提醒开始时间 + if (map.get("remindstart") != null) { + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); + c.setTime(new Date()); + c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加提醒天数 + remindStartDate = c.getTime(); // 获取新的开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并放入请求参数 + } + // 处理提醒结束时间 + if (map.get("remindend") != null) { + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); + c.setTime(new Date()); + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 添加提醒天数 + remindEndDate = c.getTime(); // 获取新的结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并放入请求参数 + } + } + + // 构建查询条件 + Wrapper wrapper = new EntityWrapper(); + if (map.get("remindstart") != null) { + wrapper.ge(columnName, map.get("remindstart")); // 大于等于开始日期 + } + if (map.get("remindend") != null) { + wrapper.le(columnName, map.get("remindend")); // 小于等于结束日期 + } + + int count = leixingService.selectCount(wrapper); // 查询数量 + return R.ok().put("count", count); // 返回数量 + } } diff --git a/src/main/java/com/controller/WenjuandiaochaController.java b/src/main/java/com/controller/WenjuandiaochaController.java index 6151049..8dbfe6f 100644 --- a/src/main/java/com/controller/WenjuandiaochaController.java +++ b/src/main/java/com/controller/WenjuandiaochaController.java @@ -52,331 +52,240 @@ import com.entity.StoreupEntity; @RequestMapping("/wenjuandiaocha") public class WenjuandiaochaController { @Autowired - private WenjuandiaochaService wenjuandiaochaService; - + private WenjuandiaochaService wenjuandiaochaService; // 注入问卷调查服务 @Autowired - private StoreupService storeupService; - - - + private StoreupService storeupService; // 注入收藏服务 /** - * 后端列表 - */ - @RequestMapping("/page") - public R page(@RequestParam Map params,WenjuandiaochaEntity wenjuandiaocha, - HttpServletRequest request){ - - EntityWrapper ew = new EntityWrapper(); - - PageUtils page = wenjuandiaochaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); - } - - /** - * 前端列表 - */ - @IgnoreAuth - @RequestMapping("/list") - public R list(@RequestParam Map params,WenjuandiaochaEntity wenjuandiaocha, - HttpServletRequest request){ - EntityWrapper ew = new EntityWrapper(); - - PageUtils page = wenjuandiaochaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); - request.setAttribute("data", page); - return R.ok().put("data", page); - } - - /** - * 列表 + * 提醒接口 */ - @RequestMapping("/lists") - public R list( WenjuandiaochaEntity wenjuandiaocha){ - EntityWrapper ew = new EntityWrapper(); - ew.allEq(MPUtil.allEQMapPre( wenjuandiaocha, "wenjuandiaocha")); - return R.ok().put("data", wenjuandiaochaService.selectListView(ew)); - } + @RequestMapping("/remind/{columnName}/{type}") + public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, + @PathVariable("type") String type, @RequestParam Map map) { + // 将列名和类型添加到 map 中 + map.put("column", columnName); + map.put("type", type); + + // 如果类型为 "2",处理日期范围 + if (type.equals("2")) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 定义日期格式 + Calendar c = Calendar.getInstance(); // 获取当前日期时间 + Date remindStartDate = null; + Date remindEndDate = null; + + // 处理 remindstart 参数 + if (map.get("remindstart") != null) { + Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); // 将 remindstart 转换为整数 + c.setTime(new Date()); // 设置当前时间 + c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加 remindStart 天 + remindStartDate = c.getTime(); // 获取新的开始日期 + map.put("remindstart", sdf.format(remindStartDate)); // 格式化并添加到 map 中 + } + + // 处理 remindend 参数 + if (map.get("remindend") != null) { + Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); // 将 remindend 转换为整数 + c.setTime(new Date()); // 设置当前时间 + c.add(Calendar.DAY_OF_MONTH, remindEnd); // 添加 remindEnd 天 + remindEndDate = c.getTime(); // 获取新的结束日期 + map.put("remindend", sdf.format(remindEndDate)); // 格式化并添加到 map 中 + } + } + + // 创建 EntityWrapper 对象,用于构建查询条件 + Wrapper wrapper = new EntityWrapper(); + if (map.get("remindstart") != null) { + wrapper.ge(columnName, map.get("remindstart")); // 大于等于 remindstart + } + if (map.get("remindend") != null) { + wrapper.le(columnName, map.get("remindend")); // 小于等于 remindend + } - /** - * 查询 - */ - @RequestMapping("/query") - public R query(WenjuandiaochaEntity wenjuandiaocha){ - EntityWrapper< WenjuandiaochaEntity> ew = new EntityWrapper< WenjuandiaochaEntity>(); - ew.allEq(MPUtil.allEQMapPre( wenjuandiaocha, "wenjuandiaocha")); - WenjuandiaochaView wenjuandiaochaView = wenjuandiaochaService.selectView(ew); - return R.ok("查询问卷调查成功").put("data", wenjuandiaochaView); + // 查询符合条件的记录数 + int count = wenjuandiaochaService.selectCount(wrapper); + return R.ok().put("count", count); // 返回记录数 } /** - * 后端详情 - */ - @RequestMapping("/info/{id}") - public R info(@PathVariable("id") Long id){ - WenjuandiaochaEntity wenjuandiaocha = wenjuandiaochaService.selectById(id); - wenjuandiaocha.setClicktime(new Date()); - wenjuandiaochaService.updateById(wenjuandiaocha); - return R.ok().put("data", wenjuandiaocha); - } - - /** - * 前端详情 - */ - @IgnoreAuth - @RequestMapping("/detail/{id}") - public R detail(@PathVariable("id") Long id){ - WenjuandiaochaEntity wenjuandiaocha = wenjuandiaochaService.selectById(id); - wenjuandiaocha.setClicktime(new Date()); - wenjuandiaochaService.updateById(wenjuandiaocha); - return R.ok().put("data", wenjuandiaocha); - } - - - - - /** - * 后端保存 - */ - @RequestMapping("/save") - public R save(@RequestBody WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request){ - wenjuandiaocha.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(wenjuandiaocha); - - wenjuandiaochaService.insert(wenjuandiaocha); - return R.ok(); - } - - /** - * 前端保存 - */ - @RequestMapping("/add") - public R add(@RequestBody WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request){ - wenjuandiaocha.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); - //ValidatorUtils.validateEntity(wenjuandiaocha); - - wenjuandiaochaService.insert(wenjuandiaocha); - return R.ok(); - } - - - /** - * 修改 - */ - @RequestMapping("/update") - @Transactional - public R update(@RequestBody WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request){ - //ValidatorUtils.validateEntity(wenjuandiaocha); - wenjuandiaochaService.updateById(wenjuandiaocha);//全部更新 - return R.ok(); - } - - - - /** - * 删除 - */ - @RequestMapping("/delete") - public R delete(@RequestBody Long[] ids){ - wenjuandiaochaService.deleteBatchIds(Arrays.asList(ids)); - return R.ok(); - } - - /** - * 提醒接口 - */ - @RequestMapping("/remind/{columnName}/{type}") - public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, - @PathVariable("type") String type,@RequestParam Map map) { - map.put("column", columnName); - map.put("type", type); - - if(type.equals("2")) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Calendar c = Calendar.getInstance(); - Date remindStartDate = null; - Date remindEndDate = null; - if(map.get("remindstart")!=null) { - Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindStart); - remindStartDate = c.getTime(); - map.put("remindstart", sdf.format(remindStartDate)); - } - if(map.get("remindend")!=null) { - Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); - c.setTime(new Date()); - c.add(Calendar.DAY_OF_MONTH,remindEnd); - remindEndDate = c.getTime(); - map.put("remindend", sdf.format(remindEndDate)); - } - } - - Wrapper wrapper = new EntityWrapper(); - if(map.get("remindstart")!=null) { - wrapper.ge(columnName, map.get("remindstart")); - } - if(map.get("remindend")!=null) { - wrapper.le(columnName, map.get("remindend")); - } - - - int count = wenjuandiaochaService.selectCount(wrapper); - return R.ok().put("count", count); - } - - - /** * 前端智能排序 */ - @IgnoreAuth + @IgnoreAuth // 忽略认证 @RequestMapping("/autoSort") - public R autoSort(@RequestParam Map params,WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request,String pre){ + public R autoSort(@RequestParam Map params, WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request, String pre) { + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); Map newMap = new HashMap(); Map param = new HashMap(); - Iterator> it = param.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); - String key = entry.getKey(); - String newKey = entry.getKey(); - if (pre.endsWith(".")) { - newMap.put(pre + newKey, entry.getValue()); - } else if (StringUtils.isEmpty(pre)) { - newMap.put(newKey, entry.getValue()); - } else { - newMap.put(pre + "." + newKey, entry.getValue()); - } - } - params.put("sort", "clicktime"); + Iterator> it = param.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + String key = entry.getKey(); + String newKey = entry.getKey(); + + // 处理 pre 参数 + if (pre.endsWith(".")) { + newMap.put(pre + newKey, entry.getValue()); + } else if (StringUtils.isEmpty(pre)) { + newMap.put(newKey, entry.getValue()); + } else { + newMap.put(pre + "." + newKey, entry.getValue()); + } + } + + // 设置排序条件 + params.put("sort", "clicktime"); params.put("order", "desc"); - PageUtils page = wenjuandiaochaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); - return R.ok().put("data", page); + + // 查询分页数据 + PageUtils page = wenjuandiaochaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); + return R.ok().put("data", page); // 返回分页数据 } /** * 协同算法(按收藏推荐) */ @RequestMapping("/autoSort2") - public R autoSort2(@RequestParam Map params,WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request){ + public R autoSort2(@RequestParam Map params, WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request) { + // 获取用户 ID String userId = request.getSession().getAttribute("userId").toString(); - String inteltypeColumn = "leixing"; + String inteltypeColumn = "leixing"; // 定义智能类型列名 List storeups = storeupService.selectList(new EntityWrapper().eq("type", 1).eq("userid", userId).eq("tablename", "wenjuandiaocha").orderBy("addtime", false)); List inteltypes = new ArrayList(); - Integer limit = params.get("limit")==null?10:Integer.parseInt(params.get("limit").toString()); + Integer limit = params.get("limit") == null ? 10 : Integer.parseInt(params.get("limit").toString()); // 设置限制数量,默认为 10 List wenjuandiaochaList = new ArrayList(); - //去重 - if(storeups!=null && storeups.size()>0) { - for(StoreupEntity s : storeups) { + + // 去重 + if (storeups != null && storeups.size() > 0) { + for (StoreupEntity s : storeups) { wenjuandiaochaList.addAll(wenjuandiaochaService.selectList(new EntityWrapper().eq(inteltypeColumn, s.getInteltype()))); } } + + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); params.put("sort", "id"); params.put("order", "desc"); + + // 查询分页数据 PageUtils page = wenjuandiaochaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); - List pageList = (List)page.getList(); - if(wenjuandiaochaList.size() pageList = (List) page.getList(); + + // 如果结果数量小于限制数量,则从分页数据中添加 + if (wenjuandiaochaList.size() < limit) { + int toAddNum = (limit - wenjuandiaochaList.size()) <= pageList.size() ? (limit - wenjuandiaochaList.size()) : pageList.size(); + for (WenjuandiaochaEntity o1 : pageList) { boolean addFlag = true; - for(WenjuandiaochaEntity o2 : wenjuandiaochaList) { - if(o1.getId().intValue()==o2.getId().intValue()) { + for (WenjuandiaochaEntity o2 : wenjuandiaochaList) { + if (o1.getId().intValue() == o2.getId().intValue()) { addFlag = false; break; } } - if(addFlag) { + if (addFlag) { wenjuandiaochaList.add(o1); - if(--toAddNum==0) break; + if (--toAddNum == 0) break; } } - } else if(wenjuandiaochaList.size()>limit) { - wenjuandiaochaList = wenjuandiaochaList.subList(0, limit); + } else if (wenjuandiaochaList.size() > limit) { + wenjuandiaochaList = wenjuandiaochaList.subList(0, limit); // 如果结果数量大于限制数量,则截取前 limit 个 } - page.setList(wenjuandiaochaList); - return R.ok().put("data", page); + + page.setList(wenjuandiaochaList); // 设置新的列表 + return R.ok().put("data", page); // 返回分页数据 } - - - /** * (按值统计) */ @RequestMapping("/value/{xColumnName}/{yColumnName}") - public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) { + public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, HttpServletRequest request) { Map params = new HashMap(); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); + + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); + + // 查询统计结果 List> result = wenjuandiaochaService.selectValue(params, ew); + + // 处理日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + for (Map m : result) { + for (String k : m.keySet()) { + if (m.get(k) instanceof Date) { + m.put(k, sdf.format((Date) m.get(k))); } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回统计结果 } /** * (按值统计)时间统计类型 */ @RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}") - public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,HttpServletRequest request) { + public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType, HttpServletRequest request) { Map params = new HashMap(); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); params.put("timeStatType", timeStatType); + + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); + + // 查询时间统计结果 List> result = wenjuandiaochaService.selectTimeStatValue(params, ew); + + // 处理日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + for (Map m : result) { + for (String k : m.keySet()) { + if (m.get(k) instanceof Date) { + m.put(k, sdf.format((Date) m.get(k))); } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回时间统计结果 } /** * 分组统计 */ @RequestMapping("/group/{columnName}") - public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) { + public R group(@PathVariable("columnName") String columnName, HttpServletRequest request) { Map params = new HashMap(); params.put("column", columnName); + + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); + + // 查询分组统计结果 List> result = wenjuandiaochaService.selectGroup(params, ew); + + // 处理日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - for(Map m : result) { - for(String k : m.keySet()) { - if(m.get(k) instanceof Date) { - m.put(k, sdf.format((Date)m.get(k))); + for (Map m : result) { + for (String k : m.keySet()) { + if (m.get(k) instanceof Date) { + m.put(k, sdf.format((Date) m.get(k))); } } } - return R.ok().put("data", result); + return R.ok().put("data", result); // 返回分组统计结果 } - - - /** * 总数量 */ @RequestMapping("/count") - public R count(@RequestParam Map params,WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request){ + public R count(@RequestParam Map params, WenjuandiaochaEntity wenjuandiaocha, HttpServletRequest request) { + // 创建 EntityWrapper 对象,用于构建查询条件 EntityWrapper ew = new EntityWrapper(); + + // 查询符合条件的记录数 int count = wenjuandiaochaService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, wenjuandiaocha), params), params)); - return R.ok().put("data", count); + return R.ok().put("data", count); // 返回记录数 } - - } diff --git a/src/main/java/com/dao/ConfigDao.java b/src/main/java/com/dao/ConfigDao.java index 3b1a357..b8aedb6 100644 --- a/src/main/java/com/dao/ConfigDao.java +++ b/src/main/java/com/dao/ConfigDao.java @@ -1,12 +1,15 @@ package com.dao; -import com.baomidou.mybatisplus.mapper.BaseMapper; -import com.entity.ConfigEntity; +import com.baomidou.mybatisplus.mapper.BaseMapper; // 导入MyBatis-Plus的BaseMapper接口 +import com.entity.ConfigEntity; // 导入配置实体类 /** - * 配置 + * 配置 DAO 接口 + * 该接口用于数据访问层,对ConfigEntity实体的数据库操作 */ public interface ConfigDao extends BaseMapper { - + // ConfigDao接口继承了BaseMapper接口,意味着它自动获得了CRUD方法 + // 可以根据需要在此处添加自定义的方法 } + diff --git a/src/main/java/com/dao/ForumDao.java b/src/main/java/com/dao/ForumDao.java index ec6e5b8..eb27fa7 100644 --- a/src/main/java/com/dao/ForumDao.java +++ b/src/main/java/com/dao/ForumDao.java @@ -1,35 +1,59 @@ package com.dao; -import com.entity.ForumEntity; -import com.baomidou.mybatisplus.mapper.BaseMapper; -import java.util.List; -import java.util.Map; +import com.entity.ForumEntity; // 导入论坛实体类 +import com.baomidou.mybatisplus.mapper.BaseMapper; // 导入MyBatis-Plus的BaseMapper接口 +import java.util.List; +import java.util.Map; import com.baomidou.mybatisplus.mapper.Wrapper; -import com.baomidou.mybatisplus.plugins.pagination.Pagination; +import com.baomidou.mybatisplus.plugins.pagination.Pagination; import org.apache.ibatis.annotations.Param; -import com.entity.vo.ForumVO; -import com.entity.view.ForumView; - +import com.entity.vo.ForumVO; // 导入论坛VO类 +import com.entity.view.ForumView; // 导入论坛视图类 /** - * 论坛表 + * 论坛表 DAO 接口 + * 该接口用于数据访问层,对ForumEntity实体的数据库操作 * * @author * @email * @date 2023-02-21 09:46:06 */ public interface ForumDao extends BaseMapper { - - List selectListVO(@Param("ew") Wrapper wrapper); - - ForumVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(@Param("ew") Wrapper wrapper); - - List selectListView(Pagination page,@Param("ew") Wrapper wrapper); - - ForumView selectView(@Param("ew") Wrapper wrapper); - + + /** + * 查询论坛列表,返回VO对象列表 + * @param wrapper 查询条件包装器 + * @return 论坛VO对象列表 + */ + List selectListVO(@Param("ew") Wrapper wrapper); + + /** + * 查询单个论坛,返回VO对象 + * @param wrapper 查询条件包装器 + * @return 论坛VO对象 + */ + ForumVO selectVO(@Param("ew") Wrapper wrapper); + + /** + * 查询论坛列表,返回视图对象列表 + * @param wrapper 查询条件包装器 + * @return 论坛视图对象列表 + */ + List selectListView(@Param("ew") Wrapper wrapper); + /** + * 分页查询论坛列表,返回视图对象列表 + * @param page 分页对象 + * @param wrapper 查询条件包装器 + * @return 论坛视图对象列表 + */ + List selectListView(Pagination page, @Param("ew") Wrapper wrapper); + + /** + * 查询单个论坛,返回视图对象 + * @param wrapper 查询条件包装器 + * @return 论坛视图对象 + */ + ForumView selectView(@Param("ew") Wrapper wrapper); } diff --git a/src/main/java/com/dao/LeixingDao.java b/src/main/java/com/dao/LeixingDao.java index 469b081..ffc32f5 100644 --- a/src/main/java/com/dao/LeixingDao.java +++ b/src/main/java/com/dao/LeixingDao.java @@ -1,35 +1,59 @@ package com.dao; -import com.entity.LeixingEntity; -import com.baomidou.mybatisplus.mapper.BaseMapper; -import java.util.List; -import java.util.Map; -import com.baomidou.mybatisplus.mapper.Wrapper; +import com.entity.LeixingEntity; +import com.baomidou.mybatisplus.mapper.BaseMapper; +import java.util.List; +import java.util.Map; +import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.plugins.pagination.Pagination; -import org.apache.ibatis.annotations.Param; -import com.entity.vo.LeixingVO; -import com.entity.view.LeixingView; - +import org.apache.ibatis.annotations.Param; +import com.entity.vo.LeixingVO; // 导入类型VO类 +import com.entity.view.LeixingView; /** - * 类型 + * 类型 DAO 接口 + * 该接口用于与数据库交互,操作LeixingEntity实体 * * @author * @email * @date 2023-02-21 09:46:06 */ public interface LeixingDao extends BaseMapper { - - List selectListVO(@Param("ew") Wrapper wrapper); - - LeixingVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(@Param("ew") Wrapper wrapper); - - List selectListView(Pagination page,@Param("ew") Wrapper wrapper); - - LeixingView selectView(@Param("ew") Wrapper wrapper); - + + /** + * 查询类型列表,返回VO对象列表 + * @param wrapper 查询条件包装器 + * @return 类型VO对象列表 + */ + List selectListVO(@Param("ew") Wrapper wrapper); + + /** + * 查询单个类型,返回VO对象 + * @param wrapper 查询条件包装器 + * @return 单个类型VO对象 + */ + LeixingVO selectVO(@Param("ew") Wrapper wrapper); + + /** + * 查询类型列表,返回视图对象列表 + * @param wrapper 查询条件包装器 + * @return 类型视图对象列表 + */ + List selectListView(@Param("ew") Wrapper wrapper); + /** + * 分页查询类型列表,返回视图对象列表 + * @param page 分页对象 + * @param wrapper 查询条件包装器 + * @return 分页后的类型视图对象列表 + */ + List selectListView(Pagination page, @Param("ew") Wrapper wrapper); + + /** + * 查询单个类型,返回视图对象 + * @param wrapper 查询条件包装器 + * @return 单个类型视图对象 + */ + LeixingView selectView(@Param("ew") Wrapper wrapper); } diff --git a/src/main/java/com/dao/WenjuandiaochaDao.java b/src/main/java/com/dao/WenjuandiaochaDao.java index 2367e7a..c472bf7 100644 --- a/src/main/java/com/dao/WenjuandiaochaDao.java +++ b/src/main/java/com/dao/WenjuandiaochaDao.java @@ -13,31 +13,73 @@ import com.entity.view.WenjuandiaochaView; /** - * 问卷调查 - * - * @author - * @email + * 问卷调查数据访问对象接口 + * 该接口继承自BaseMapper,提供了基本的CRUD操作方法 + * @author 未填写具体作者 + * @email 未填写具体邮箱 * @date 2023-02-21 09:46:06 */ public interface WenjuandiaochaDao extends BaseMapper { - - List selectListVO(@Param("ew") Wrapper wrapper); - - WenjuandiaochaVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(@Param("ew") Wrapper wrapper); - List selectListView(Pagination page,@Param("ew") Wrapper wrapper); - - WenjuandiaochaView selectView(@Param("ew") Wrapper wrapper); - + /** + * 根据条件查询问卷调查列表,并将结果转换为WenjuandiaochaVO对象列表 + * @param ew 查询条件封装对象 + * @return 符合条件的问卷调查VO对象列表 + */ + List selectListVO(@Param("ew") Wrapper ew); - List> selectValue(@Param("params") Map params,@Param("ew") Wrapper wrapper); + /** + * 根据条件查询单个问卷调查记录,并将其转换为WenjuandiaochaVO对象 + * @param ew 查询条件封装对象 + * @return 符合条件的问卷调查VO对象 + */ + WenjuandiaochaVO selectVO(@Param("ew") Wrapper ew); - List> selectTimeStatValue(@Param("params") Map params,@Param("ew") Wrapper wrapper); - - List> selectGroup(@Param("params") Map params,@Param("ew") Wrapper wrapper); + /** + * 根据条件查询问卷调查列表,并将结果转换为WenjuandiaochaView对象列表 + * @param ew 查询条件封装对象 + * @return 符合条件的问卷调查View对象列表 + */ + List selectListView(@Param("ew") Wrapper ew); + /** + * 根据条件和分页参数查询问卷调查列表,并将结果转换为WenjuandiaochaView对象列表 + * @param page 分页参数对象 + * @param ew 查询条件封装对象 + * @return 分页后的符合条件的问卷调查View对象列表 + */ + List selectListView(Pagination page, @Param("ew") Wrapper ew); + /** + * 根据条件查询单个问卷调查记录,并将其转换为WenjuandiaochaView对象 + * @param ew 查询条件封装对象 + * @return 符合条件的问卷调查View对象 + */ + WenjuandiaochaView selectView(@Param("ew") Wrapper ew); + + /** + * 根据自定义参数和条件查询数据库,并返回Map对象列表 + * @param params 自定义查询参数 + * @param ew 查询条件封装对象 + * @return 符合条件的数据结果集,返回值为Map对象列表 + */ + List> selectValue(@Param("params") Map params, @Param("ew") Wrapper ew); + + /** + * 根据时间统计自定义参数和条件查询数据库,并返回Map对象列表 + * @param params 自定义查询参数,可能包含时间范围等信息 + * @param ew 查询条件封装对象 + * @return 符合条件的时间统计数据结果集,返回值为Map对象列表 + */ + List> selectTimeStatValue(@Param("params") Map params, @Param("ew") Wrapper ew); + + /** + * 根据分组查询自定义参数和条件查询数据库,并返回Map对象列表 + * @param params 自定义查询参数,可能包含分组依据等信息 + * @param ew 查询条件封装对象 + * @return 符合条件的分组数据结果集,返回值为Map对象列表 + */ + List> selectGroup(@Param("params") Map params, @Param("ew") Wrapper ew); } + diff --git a/src/main/java/com/entity/ConfigEntity.java b/src/main/java/com/entity/ConfigEntity.java index 57872be..f63330f 100644 --- a/src/main/java/com/entity/ConfigEntity.java +++ b/src/main/java/com/entity/ConfigEntity.java @@ -9,25 +9,25 @@ import com.baomidou.mybatisplus.enums.IdType; /** * 类说明 : */ -@TableName("config") +@TableName("config")// 指定该类对应的数据库表名为"config" public class ConfigEntity implements Serializable{ private static final long serialVersionUID = 1L; - @TableId(type = IdType.AUTO) + @TableId(type = IdType.AUTO) // 主键ID,使用自增长方式 private Long id; /** - * key - */ + * 配置项的名称(键) + */ private String name; /** - * value - */ + * 配置项的值 + */ private String value; public Long getId() { - return id; + return id; // 返回配置ID } public void setId(Long id) { @@ -39,7 +39,7 @@ private static final long serialVersionUID = 1L; } public void setName(String name) { - this.name = name; + this.name = name;//设置配置名称 } public String getValue() { @@ -47,7 +47,7 @@ private static final long serialVersionUID = 1L; } public void setValue(String value) { - this.value = value; + this.value = value;// 设置配置值 } } diff --git a/src/main/java/com/entity/ForumEntity.java b/src/main/java/com/entity/ForumEntity.java index 59cbac2..0b22e6f 100644 --- a/src/main/java/com/entity/ForumEntity.java +++ b/src/main/java/com/entity/ForumEntity.java @@ -16,6 +16,8 @@ import java.util.List; import org.springframework.format.annotation.DateTimeFormat; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.beanutils.BeanUtils; +import org.apache.poi.ss.formula.functions.T; + import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.enums.FieldFill; import com.baomidou.mybatisplus.enums.IdType; @@ -37,14 +39,15 @@ public class ForumEntity implements Serializable { } - public ForumEntity(T t) { - try { - BeanUtils.copyProperties(this, t); - } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + // 接收ForumEntity对象的构造函数 + public ForumEntity(T t) { + try { + // 复制属性,将传入对象的属性复制到当前对象 + BeanUtils.copyProperties(this, t); + } catch (IllegalAccessException | InvocationTargetException e) { + // 异常处理,打印堆栈信息 + e.printStackTrace(); + } /** * 主键id @@ -99,10 +102,10 @@ public class ForumEntity implements Serializable { private Date addtime; public Date getAddtime() { - return addtime; + return addtime;// 返回添加时间 } public void setAddtime(Date addtime) { - this.addtime = addtime; + this.addtime = addtime;// 设置添加时间 } public Long getId() { @@ -110,9 +113,12 @@ public class ForumEntity implements Serializable { } public void setId(Long id) { - this.id = id; + this.id = id;// 设置帖子ID } - @TableField(exist = false) + /** + * 存放子帖子的列表 + */ + @TableField(exist = false) // 该字段不在数据库表中存在 private List childs; public List getChilds() { @@ -120,7 +126,7 @@ public class ForumEntity implements Serializable { } public void setChilds(List childs) { - this.childs = childs; + this.childs = childs;// 设置子帖子 } /** * 设置:帖子标题 diff --git a/src/main/java/com/entity/LeixingEntity.java b/src/main/java/com/entity/LeixingEntity.java index fa59521..675991e 100644 --- a/src/main/java/com/entity/LeixingEntity.java +++ b/src/main/java/com/entity/LeixingEntity.java @@ -16,6 +16,8 @@ import java.util.List; import org.springframework.format.annotation.DateTimeFormat; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.beanutils.BeanUtils; +import org.apache.poi.ss.formula.functions.T; + import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.enums.FieldFill; import com.baomidou.mybatisplus.enums.IdType; @@ -37,11 +39,13 @@ public class LeixingEntity implements Serializable { } + // 接收LeixingEntity对象的构造函数 public LeixingEntity(T t) { try { + // 复制属性,将传入对象的属性复制到当前对象 BeanUtils.copyProperties(this, t); } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block + // 异常处理,打印堆栈信息 e.printStackTrace(); } } @@ -58,15 +62,15 @@ public class LeixingEntity implements Serializable { private String leixing; - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat - private Date addtime; + @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")// 指定JSON格式化 + @DateTimeFormat// 用于Spring格式化 + private Date addtime;// 存放添加时间 public Date getAddtime() { return addtime; } public void setAddtime(Date addtime) { - this.addtime = addtime; + this.addtime = addtime;// 设置添加时间 } public Long getId() { @@ -74,7 +78,7 @@ public class LeixingEntity implements Serializable { } public void setId(Long id) { - this.id = id; + this.id = id;// 设置类型ID } /** * 设置:类型 diff --git a/src/main/java/com/entity/WenjuandiaochaEntity.java b/src/main/java/com/entity/WenjuandiaochaEntity.java index d826017..2d33f1f 100644 --- a/src/main/java/com/entity/WenjuandiaochaEntity.java +++ b/src/main/java/com/entity/WenjuandiaochaEntity.java @@ -3,7 +3,6 @@ package com.entity; import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableName; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -11,37 +10,39 @@ import java.lang.reflect.InvocationTargetException; import java.io.Serializable; import java.util.Date; -import java.util.List; import org.springframework.format.annotation.DateTimeFormat; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.beanutils.BeanUtils; -import com.baomidou.mybatisplus.annotations.TableField; -import com.baomidou.mybatisplus.enums.FieldFill; -import com.baomidou.mybatisplus.enums.IdType; - /** * 问卷调查 * 数据库通用操作实体类(普通增删改查) - * @author - * @email + * @author 作者名 + * @email 邮箱地址 * @date 2023-02-21 09:46:06 */ -@TableName("wenjuandiaocha") -public class WenjuandiaochaEntity implements Serializable { - private static final long serialVersionUID = 1L; - +@TableName("wenjuandiaocha") // 指定该实体类对应的数据库表名为“wenjuandiaocha” +@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未知属性,防止反序列化时出现错误 +public class WenjuandiaochaEntity implements Serializable { // 实现Serializable接口以支持序列化 + private static final long serialVersionUID = 1L; // 序列化版本号 + /** + * 无参构造函数 + */ public WenjuandiaochaEntity() { } + /** + * 带泛型参数的构造函数,用于从传入的对象t中复制属性值 + * @param t 传入的对象,其属性将被复制到当前实体对象中 + */ public WenjuandiaochaEntity(T t) { try { - BeanUtils.copyProperties(this, t); + BeanUtils.copyProperties(this, t); // 使用BeanUtils工具类复制属性 } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block + // 打印堆栈跟踪信息以便调试 e.printStackTrace(); } } @@ -49,210 +50,274 @@ public class WenjuandiaochaEntity implements Serializable { /** * 主键id */ - @TableId + @TableId // 指定该字段为主键 private Long id; + /** * 问卷标题 + * 使用NotBlank注解确保问卷标题不为空字符串 */ - + @NotBlank(message = "问卷标题不能为空") private String wenjuanbiaoti; /** * 封面图片 + * 使用NotBlank注解确保封面图片路径不为空字符串 */ - + @NotBlank(message = "封面图片路径不能为空") private String fengmiantupian; /** * 类型 + * 使用NotBlank注解确保类型不为空字符串 */ - + @NotBlank(message = "类型不能为空") private String leixing; /** * 问题一 + * 使用NotBlank注解确保问题一不为空字符串 */ - + @NotBlank(message = "问题一不能为空") private String wentiyi; /** * 问题二 + * 使用NotBlank注解确保问题二不为空字符串 */ - + @NotBlank(message = "问题二不能为空") private String wentier; /** * 问题三 + * 使用NotBlank注解确保问题三不为空字符串 */ - + @NotBlank(message = "问题三不能为空") private String wentisan; /** * 问题四 + * 使用NotBlank注解确保问题四不为空字符串 */ - + @NotBlank(message = "问题四不能为空") private String wentisi; /** * 问题五 + * 使用NotBlank注解确保问题五不为空字符串 */ - + @NotBlank(message = "问题五不能为空") private String wentiwu; /** * 发布日期 + * 使用JsonFormat注解指定日期格式为“yyyy-MM-dd HH:mm:ss”,时区为东八区 + * 使用DateTimeFormat注解指定日期格式为“yyyy-MM-dd HH:mm:ss”,用于处理请求参数中的日期格式 + * 使用NotNull注解确保发布日期不为null */ - - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd") - @DateTimeFormat + @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @NotNull(message = "发布日期不能为空") private Date faburiqi; - + /** * 最近点击时间 + * 使用JsonFormat注解指定日期格式为“yyyy-MM-dd HH:mm:ss”,时区为东八区 + * 使用DateTimeFormat注解指定日期格式为“yyyy-MM-dd HH:mm:ss”,用于处理请求参数中的日期格式 */ - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date clicktime; - - - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat - private Date addtime; - public Date getAddtime() { - return addtime; - } + /** + * 设置:添加时间 + * @param addtime 问卷的添加时间 + */ public void setAddtime(Date addtime) { this.addtime = addtime; } - public Long getId() { - return id; + /** + * 获取:添加时间 + * @return 问卷的添加时间 + */ + public Date getAddtime() { + return addtime; } + /** + * 设置:主键id + * @param id 主键id + */ public void setId(Long id) { this.id = id; } - /** - * 设置:问卷标题 - */ + + /** + * 获取:主键id + * @return 主键id + */ + public Long getId() { + return id; + } + + /** + * 设置:问卷标题 + * @param wenjuanbiaoti 问卷标题 + */ public void setWenjuanbiaoti(String wenjuanbiaoti) { this.wenjuanbiaoti = wenjuanbiaoti; } - /** - * 获取:问卷标题 - */ + + /** + * 获取:问卷标题 + * @return 问卷标题 + */ public String getWenjuanbiaoti() { return wenjuanbiaoti; } - /** - * 设置:封面图片 - */ + + /** + * 设置:封面图片 + * @param fengmiantupian 封面图片路径 + */ public void setFengmiantupian(String fengmiantupian) { this.fengmiantupian = fengmiantupian; } - /** - * 获取:封面图片 - */ + + /** + * 获取:封面图片 + * @return 封面图片路径 + */ public String getFengmiantupian() { return fengmiantupian; } - /** - * 设置:类型 - */ + + /** + * 设置:类型 + * @param leixing 问卷类型 + */ public void setLeixing(String leixing) { this.leixing = leixing; } - /** - * 获取:类型 - */ + + /** + * 获取:类型 + * @return 问卷类型 + */ public String getLeixing() { return leixing; } - /** - * 设置:问题一 - */ + + /** + * 设置:问题一 + * @param wentiyi 问题一的内容 + */ public void setWentiyi(String wentiyi) { this.wentiyi = wentiyi; } - /** - * 获取:问题一 - */ + + /** + * 获取:问题一 + * @return 问题一的内容 + */ public String getWentiyi() { return wentiyi; } - /** - * 设置:问题二 - */ + + /** + * 设置:问题二 + * @param wentier 问题二的内容 + */ public void setWentier(String wentier) { this.wentier = wentier; } - /** - * 获取:问题二 - */ + + /** + * 获取:问题二 + * @return 问题二的内容 + */ public String getWentier() { return wentier; } - /** - * 设置:问题三 - */ + + /** + * 设置:问题三 + * @param wentisan 问题三的内容 + */ public void setWentisan(String wentisan) { this.wentisan = wentisan; } - /** - * 获取:问题三 - */ + + /** + * 获取:问题三 + * @return 问题三的内容 + */ public String getWentisan() { return wentisan; } - /** - * 设置:问题四 - */ + + /** + * 设置:问题四 + * @param wentisi 问题四的内容 + */ public void setWentisi(String wentisi) { this.wentisi = wentisi; } - /** - * 获取:问题四 - */ + + /** + * 获取:问题四 + * @return 问题四的内容 + */ public String getWentisi() { return wentisi; } - /** - * 设置:问题五 - */ + + /** + * 设置:问题五 + * @param wentiwu 问题五的内容 + */ public void setWentiwu(String wentiwu) { this.wentiwu = wentiwu; } - /** - * 获取:问题五 - */ + + /** + * 获取:问题五 + * @return 问题五的内容 + */ public String getWentiwu() { return wentiwu; } - /** - * 设置:发布日期 - */ + + /** + * 设置:发布日期 + * @param faburiqi 问卷的发布日期 + */ public void setFaburiqi(Date faburiqi) { this.faburiqi = faburiqi; } - /** - * 获取:发布日期 - */ + + /** + * 获取:发布日期 + * @return 问卷的发布日期 + */ public Date getFaburiqi() { return faburiqi; } - /** - * 设置:最近点击时间 - */ + + /** + * 设置:最近点击时间 + * @param clicktime 最近点击该问卷的时间 + */ public void setClicktime(Date clicktime) { this.clicktime = clicktime; } - /** - * 获取:最近点击时间 - */ + + /** + * 获取:最近点击时间 + * @return 最近点击该问卷的时间 + */ public Date getClicktime() { return clicktime; } - } diff --git a/src/main/java/com/entity/model/ForumModel.java b/src/main/java/com/entity/model/ForumModel.java index 2f9c9c0..97591fc 100644 --- a/src/main/java/com/entity/model/ForumModel.java +++ b/src/main/java/com/entity/model/ForumModel.java @@ -1,157 +1,144 @@ package com.entity.model; -import com.entity.ForumEntity; - -import com.baomidou.mybatisplus.annotations.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; -import java.util.Date; -import org.springframework.format.annotation.DateTimeFormat; -import java.io.Serializable; - +import com.entity.ForumEntity; +import java.io.Serializable; // 导入可序列化接口 /** * 论坛表 * 接收传参的实体类 - *(实际开发中配合移动端接口开发手动去掉些没用的字段, 后端一般用entity就够用了) - * 取自ModelAndView 的model名称 + * (实际开发中配合移动端接口开发手动去掉些没用的字段,后端一般用entity就够用了) + * 取自ModelAndView的model名称 + * * @author * @email * @date 2023-02-21 09:46:06 */ -public class ForumModel implements Serializable { - private static final long serialVersionUID = 1L; +public class ForumModel implements Serializable { + private static final long serialVersionUID = 1L; // 版本控制 - /** * 帖子内容 */ + private String content; // 存放帖子内容 - private String content; - /** * 父节点id */ + private Long parentid; // 存放父节点ID - private Long parentid; - /** * 用户id */ + private Long userid; // 存放用户ID - private Long userid; - /** * 用户名 */ + private String username; // 存放用户名 - private String username; - /** * 头像 */ + private String avatarurl; // 存放用户头像URL - private String avatarurl; - /** * 状态 */ - - private String isdone; - + private String isdone; // 存放帖子状态(例如:已完成/未完成等) /** * 设置:帖子内容 + * @param content 帖子内容 */ - public void setContent(String content) { - this.content = content; + this.content = content; // 设置帖子内容 } /** * 获取:帖子内容 + * @return 帖子内容 */ public String getContent() { - return content; + return content; } - /** * 设置:父节点id + * @param parentid 父节点ID */ - public void setParentid(Long parentid) { - this.parentid = parentid; + this.parentid = parentid; // 设置父节点ID } /** * 获取:父节点id + * @return 父节点ID */ public Long getParentid() { - return parentid; + return parentid; // 返回父节点ID } - /** * 设置:用户id + * @param userid 用户ID */ - public void setUserid(Long userid) { - this.userid = userid; + this.userid = userid; // 设置用户ID } /** * 获取:用户id + * @return 用户ID */ public Long getUserid() { return userid; } - /** * 设置:用户名 + * @param username 用户名 */ - public void setUsername(String username) { - this.username = username; + this.username = username; // 设置用户名 } /** * 获取:用户名 + * @return 用户名 */ public String getUsername() { - return username; + return username; } - /** * 设置:头像 + * @param avatarurl 头像URL */ - public void setAvatarurl(String avatarurl) { - this.avatarurl = avatarurl; + this.avatarurl = avatarurl; // 设置头像URL } /** * 获取:头像 + * @return 头像URL */ public String getAvatarurl() { - return avatarurl; + return avatarurl; } - /** * 设置:状态 + * @param isdone 帖子状态 */ - public void setIsdone(String isdone) { - this.isdone = isdone; + this.isdone = isdone; // 设置帖子状态 } /** * 获取:状态 + * @return 帖子状态 */ public String getIsdone() { - return isdone; + return isdone; } - } diff --git a/src/main/java/com/entity/model/LeixingModel.java b/src/main/java/com/entity/model/LeixingModel.java index 495a8ed..e71611f 100644 --- a/src/main/java/com/entity/model/LeixingModel.java +++ b/src/main/java/com/entity/model/LeixingModel.java @@ -19,7 +19,7 @@ import java.io.Serializable; * @date 2023-02-21 09:46:06 */ public class LeixingModel implements Serializable { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L;// 版本控制 + // 可以根据需求定义属性,例如类型的名称、描述等 } diff --git a/src/main/java/com/entity/model/WenjuandiaochaModel.java b/src/main/java/com/entity/model/WenjuandiaochaModel.java index 2370a3f..3473064 100644 --- a/src/main/java/com/entity/model/WenjuandiaochaModel.java +++ b/src/main/java/com/entity/model/WenjuandiaochaModel.java @@ -1,227 +1,195 @@ package com.entity.model; import com.entity.WenjuandiaochaEntity; - import com.baomidou.mybatisplus.annotations.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; - /** - * 问卷调查 - * 接收传参的实体类 - *(实际开发中配合移动端接口开发手动去掉些没用的字段, 后端一般用entity就够用了) - * 取自ModelAndView 的model名称 - * @author - * @email + * 问卷调查模型类 + * 该类用于接收传参,通常在实际开发中配合移动端接口开发时手动去掉一些不需要的字段 + * 取自ModelAndView的model名称 + * @author 未填写具体作者 + * @email 未填写具体邮箱 * @date 2023-02-21 09:46:06 */ -public class WenjuandiaochaModel implements Serializable { +public class WenjuandiaochaModel implements Serializable { private static final long serialVersionUID = 1L; - /** * 封面图片 */ - private String fengmiantupian; - + /** * 类型 */ - private String leixing; - + /** * 问题一 */ - private String wentiyi; - + /** * 问题二 */ - private String wentier; - + /** * 问题三 */ - private String wentisan; - + /** * 问题四 */ - private String wentisi; - + /** * 问题五 */ - private String wentiwu; - + /** * 发布日期 */ - - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat + @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat private Date faburiqi; - + /** * 最近点击时间 */ - - @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") - @DateTimeFormat + @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat private Date clicktime; - - + /** * 设置:封面图片 */ - public void setFengmiantupian(String fengmiantupian) { this.fengmiantupian = fengmiantupian; } - + /** * 获取:封面图片 */ public String getFengmiantupian() { return fengmiantupian; } - - + /** * 设置:类型 */ - public void setLeixing(String leixing) { this.leixing = leixing; } - + /** * 获取:类型 */ public String getLeixing() { return leixing; } - - + /** * 设置:问题一 */ - public void setWentiyi(String wentiyi) { this.wentiyi = wentiyi; } - + /** * 获取:问题一 */ public String getWentiyi() { return wentiyi; } - - + /** * 设置:问题二 */ - public void setWentier(String wentier) { this.wentier = wentier; } - + /** * 获取:问题二 */ public String getWentier() { return wentier; } - - + /** * 设置:问题三 */ - public void setWentisan(String wentisan) { this.wentisan = wentisan; } - + /** * 获取:问题三 */ public String getWentisan() { return wentisan; } - - + /** * 设置:问题四 */ - public void setWentisi(String wentisi) { this.wentisi = wentisi; } - + /** * 获取:问题四 */ public String getWentisi() { return wentisi; } - - + /** * 设置:问题五 */ - public void setWentiwu(String wentiwu) { this.wentiwu = wentiwu; } - + /** * 获取:问题五 */ public String getWentiwu() { return wentiwu; } - - + /** * 设置:发布日期 */ - public void setFaburiqi(Date faburiqi) { this.faburiqi = faburiqi; } - + /** * 获取:发布日期 */ public Date getFaburiqi() { return faburiqi; } - - + /** * 设置:最近点击时间 */ - public void setClicktime(Date clicktime) { this.clicktime = clicktime; } - + /** * 获取:最近点击时间 */ public Date getClicktime() { return clicktime; } - } diff --git a/src/main/java/com/entity/view/ForumView.java b/src/main/java/com/entity/view/ForumView.java index d2fe9c1..2bbe335 100644 --- a/src/main/java/com/entity/view/ForumView.java +++ b/src/main/java/com/entity/view/ForumView.java @@ -24,13 +24,15 @@ public class ForumView extends ForumEntity implements Serializable { public ForumView(){ } - public ForumView(ForumEntity forumEntity){ - try { + // 接收 ForumEntity 对象的构造函数 + public ForumView(ForumEntity forumEntity) { + try { + // 将ForumEntity的属性复制到当前ForumView对象 BeanUtils.copyProperties(this, forumEntity); } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block + // 异常处理,打印堆栈信息 e.printStackTrace(); } - } + } diff --git a/src/main/java/com/entity/view/LeixingView.java b/src/main/java/com/entity/view/LeixingView.java index fc3c7a4..ba7b695 100644 --- a/src/main/java/com/entity/view/LeixingView.java +++ b/src/main/java/com/entity/view/LeixingView.java @@ -24,13 +24,14 @@ public class LeixingView extends LeixingEntity implements Serializable { public LeixingView(){ } - public LeixingView(LeixingEntity leixingEntity){ - try { + // 接收 LeixingEntity 对象的构造函数 + public LeixingView(LeixingEntity leixingEntity) { + try { + // 将LeixingEntity的属性复制到当前LeixingView对象 BeanUtils.copyProperties(this, leixingEntity); } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block + // 异常处理,打印堆栈信息 e.printStackTrace(); } - } } diff --git a/src/main/java/com/entity/view/WenjuandiaochaView.java b/src/main/java/com/entity/view/WenjuandiaochaView.java index e176a43..e7f6427 100644 --- a/src/main/java/com/entity/view/WenjuandiaochaView.java +++ b/src/main/java/com/entity/view/WenjuandiaochaView.java @@ -1,36 +1,40 @@ package com.entity.view; import com.entity.WenjuandiaochaEntity; - import com.baomidou.mybatisplus.annotations.TableName; import org.apache.commons.beanutils.BeanUtils; import java.lang.reflect.InvocationTargetException; import java.io.Serializable; - /** - * 问卷调查 - * 后端返回视图实体辅助类 - * (通常后端关联的表或者自定义的字段需要返回使用) - * @author - * @email + * 问卷调查视图实体类 + * 该类用于在后端返回视图时使用的辅助实体类。 + * 通常在后端需要关联其他表或自定义字段时,会使用此类来封装返回的数据。 + * @author 未填写具体作者 + * @email 未填写具体邮箱 * @date 2023-02-21 09:46:06 */ @TableName("wenjuandiaocha") -public class WenjuandiaochaView extends WenjuandiaochaEntity implements Serializable { - private static final long serialVersionUID = 1L; +public class WenjuandiaochaView extends WenjuandiaochaEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 无参构造函数 + */ + public WenjuandiaochaView() { + } - public WenjuandiaochaView(){ - } - - public WenjuandiaochaView(WenjuandiaochaEntity wenjuandiaochaEntity){ - try { - BeanUtils.copyProperties(this, wenjuandiaochaEntity); - } catch (IllegalAccessException | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } + /** + * 带参数的构造函数,用于将WenjuandiaochaEntity对象的属性复制到WenjuandiaochaView对象中 + * @param wenjuandiaochaEntity 问卷调查实体对象 + */ + public WenjuandiaochaView(WenjuandiaochaEntity wenjuandiaochaEntity) { + try { + BeanUtils.copyProperties(this, wenjuandiaochaEntity); + } catch (IllegalAccessException | InvocationTargetException e) { + // 打印堆栈跟踪信息以便调试 + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/entity/vo/LeixingVO.java b/src/main/java/com/entity/vo/LeixingVO.java index 73760b7..1cab2d0 100644 --- a/src/main/java/com/entity/vo/LeixingVO.java +++ b/src/main/java/com/entity/vo/LeixingVO.java @@ -19,7 +19,7 @@ import java.io.Serializable; * @date 2023-02-21 09:46:06 */ public class LeixingVO implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L;// 版本控制,用于序列化 } diff --git a/src/main/java/com/service/ConfigService.java b/src/main/java/com/service/ConfigService.java index edd52e9..8521dc4 100644 --- a/src/main/java/com/service/ConfigService.java +++ b/src/main/java/com/service/ConfigService.java @@ -3,8 +3,8 @@ package com.service; import java.util.Map; -import com.baomidou.mybatisplus.mapper.Wrapper; -import com.baomidou.mybatisplus.service.IService; +import com.baomidou.mybatisplus.mapper.Wrapper;// 导入MyBatis-Plus的Wrapper接口,用于构建查询条件 +import com.baomidou.mybatisplus.service.IService;// 导入MyBatis-Plus的服务接口 import com.entity.ConfigEntity; import com.utils.PageUtils; @@ -13,5 +13,12 @@ import com.utils.PageUtils; * 系统用户 */ public interface ConfigService extends IService { - PageUtils queryPage(Map params,Wrapper wrapper); + + /** + * 查询分页数据 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 封装好的分页结果 + */ + PageUtils queryPage(Map params, Wrapper wrapper); } diff --git a/src/main/java/com/service/ForumService.java b/src/main/java/com/service/ForumService.java index 7861b3e..c925e5d 100644 --- a/src/main/java/com/service/ForumService.java +++ b/src/main/java/com/service/ForumService.java @@ -3,14 +3,12 @@ package com.service; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.service.IService; import com.utils.PageUtils; -import com.entity.ForumEntity; +import com.entity.ForumEntity; // 导入论坛实体类 import java.util.List; import java.util.Map; -import com.entity.vo.ForumVO; +import com.entity.vo.ForumVO;// 导入论坛VO类 import org.apache.ibatis.annotations.Param; -import com.entity.view.ForumView; - - +import com.entity.view.ForumView;v// 导入论坛视图类 /** * 论坛表 * @@ -20,18 +18,47 @@ import com.entity.view.ForumView; */ public interface ForumService extends IService { + /** + * 查询分页数据 + * @param params 查询参数 + * @return 分页结果 + */ PageUtils queryPage(Map params); - List selectListVO(Wrapper wrapper); - - ForumVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(Wrapper wrapper); - - ForumView selectView(@Param("ew") Wrapper wrapper); - - PageUtils queryPage(Map params,Wrapper wrapper); - - + /** + * 查询VO列表 + * @param wrapper 查询条件包装器 + * @return ForumVO对象列表 + */ + List selectListVO(Wrapper wrapper); + + /** + * 查询单个VO对象 + * @param wrapper 查询条件包装器 + * @return 单个ForumVO对象 + */ + ForumVO selectVO(@Param("ew") Wrapper wrapper); + + /** + * 查询视图列表 + * @param wrapper 查询条件包装器 + * @return ForumView对象列表 + */ + List selectListView(Wrapper wrapper); + + /** + * 查询单个视图对象 + * @param wrapper 查询条件包装器 + * @return 单个ForumView对象 + */ + ForumView selectView(@Param("ew") Wrapper wrapper); + + /** + * 带条件的查询分页数据 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ + PageUtils queryPage(Map params, Wrapper wrapper); } diff --git a/src/main/java/com/service/LeixingService.java b/src/main/java/com/service/LeixingService.java index 17c4ffc..483af41 100644 --- a/src/main/java/com/service/LeixingService.java +++ b/src/main/java/com/service/LeixingService.java @@ -3,12 +3,12 @@ package com.service; import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.service.IService; import com.utils.PageUtils; -import com.entity.LeixingEntity; +import com.entity.LeixingEntity; // 导入类型实体类 import java.util.List; import java.util.Map; import com.entity.vo.LeixingVO; import org.apache.ibatis.annotations.Param; -import com.entity.view.LeixingView; +import com.entity.view.LeixingView;// 导入类型视图类 /** @@ -20,18 +20,47 @@ import com.entity.view.LeixingView; */ public interface LeixingService extends IService { + /** + * 查询分页数据 + * @param params 查询参数 + * @return 分页结果 + */ PageUtils queryPage(Map params); - List selectListVO(Wrapper wrapper); - - LeixingVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(Wrapper wrapper); - - LeixingView selectView(@Param("ew") Wrapper wrapper); - - PageUtils queryPage(Map params,Wrapper wrapper); - - + /** + * 查询类型列表,返回VO对象列表 + * @param wrapper 查询条件包装器 + * @return LeixingVO对象列表 + */ + List selectListVO(Wrapper wrapper); + + /** + * 查询单个类型,返回VO对象 + * @param wrapper 查询条件包装器 + * @return 单个LeixingVO对象 + */ + LeixingVO selectVO(@Param("ew") Wrapper wrapper); + + /** + * 查询类型列表,返回视图对象列表 + * @param wrapper 查询条件包装器 + * @return LeixingView对象列表 + */ + List selectListView(Wrapper wrapper); + + /** + * 查询单个类型,返回视图对象 + * @param wrapper 查询条件包装器 + * @return 单个LeixingView对象 + */ + LeixingView selectView(@Param("ew") Wrapper wrapper); + + /** + * 带条件的查询分页数据 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ + PageUtils queryPage(Map params, Wrapper wrapper); } diff --git a/src/main/java/com/service/WenjuandafuService.java b/src/main/java/com/service/WenjuandafuService.java index 709265b..6b6212b 100644 --- a/src/main/java/com/service/WenjuandafuService.java +++ b/src/main/java/com/service/WenjuandafuService.java @@ -20,26 +20,70 @@ import com.entity.view.WenjuandafuView; */ public interface WenjuandafuService extends IService { + /** + * 查询分页数据 + * @param params 查询参数 + * @return 分页结果 + */ PageUtils queryPage(Map params); - List selectListVO(Wrapper wrapper); - - WenjuandafuVO selectVO(@Param("ew") Wrapper wrapper); - - List selectListView(Wrapper wrapper); - - WenjuandafuView selectView(@Param("ew") Wrapper wrapper); - - PageUtils queryPage(Map params,Wrapper wrapper); - - - List> selectValue(Map params,Wrapper wrapper); - - List> selectTimeStatValue(Map params,Wrapper wrapper); + /** + * 查询问卷答复列表,返回VO对象列表 + * @param wrapper 查询条件包装器 + * @return 问卷答复VO对象列表 + */ + List selectListVO(Wrapper wrapper); - List> selectGroup(Map params,Wrapper wrapper); - + /** + * 查询单个问卷答复,返回VO对象 + * @param wrapper 查询条件包装器 + * @return 问卷答复VO对象 + */ + WenjuandafuVO selectVO(@Param("ew") Wrapper wrapper); + + /** + * 查询问卷答复列表,返回视图对象列表 + * @param wrapper 查询条件包装器 + * @return 问卷答复视图对象列表 + */ + List selectListView(Wrapper wrapper); + + /** + * 查询单个问卷答复,返回视图对象 + * @param wrapper 查询条件包装器 + * @return 问卷答复视图对象 + */ + WenjuandafuView selectView(@Param("ew") Wrapper wrapper); + + /** + * 查询分页数据 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ + PageUtils queryPage(Map params, Wrapper wrapper); + /** + * 查询问卷答复的值,以Map形式返回 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 值的Map列表 + */ + List> selectValue(Map params, Wrapper wrapper); -} + /** + * 根据时间统计查询问卷答复的值 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 时间统计值的Map列表 + */ + List> selectTimeStatValue(Map params, Wrapper wrapper); + + /** + * 查询分组统计数据 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分组统计的Map列表 + */ + List> selectGroup(Map params, Wrapper wrapper); diff --git a/src/main/java/com/service/WenjuandiaochaService.java b/src/main/java/com/service/WenjuandiaochaService.java index 8035f61..64f4643 100644 --- a/src/main/java/com/service/WenjuandiaochaService.java +++ b/src/main/java/com/service/WenjuandiaochaService.java @@ -10,36 +10,80 @@ import com.entity.vo.WenjuandiaochaVO; import org.apache.ibatis.annotations.Param; import com.entity.view.WenjuandiaochaView; - /** - * 问卷调查 + * 问卷调查服务接口 * - * @author - * @email + * @author 作者名 + * @email 邮箱地址 * @date 2023-02-21 09:46:06 */ public interface WenjuandiaochaService extends IService { + /** + * 分页查询问卷调查数据 + * @param params 查询参数 + * @return 分页结果 + */ PageUtils queryPage(Map params); - List selectListVO(Wrapper wrapper); + /** + * 查询问卷调查列表(带条件) + * @param wrapper 查询条件包装器 + * @return 问卷调查列表 + */ + List selectListVO(Wrapper wrapper); - WenjuandiaochaVO selectVO(@Param("ew") Wrapper wrapper); + /** + * 查询单个问卷调查(带条件) + * @param wrapper 查询条件包装器 + * @return 单个问卷调查 + */ + WenjuandiaochaVO selectVO(@Param("ew") Wrapper wrapper); - List selectListView(Wrapper wrapper); + /** + * 查询问卷调查视图列表(带条件) + * @param wrapper 查询条件包装器 + * @return 问卷调查视图列表 + */ + List selectListView(Wrapper wrapper); - WenjuandiaochaView selectView(@Param("ew") Wrapper wrapper); + /** + * 查询单个问卷调查视图(带条件) + * @param wrapper 查询条件包装器 + * @return 单个问卷调查视图 + */ + WenjuandiaochaView selectView(@Param("ew") Wrapper wrapper); - PageUtils queryPage(Map params,Wrapper wrapper); + /** + * 分页查询问卷调查数据(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ + PageUtils queryPage(Map params, Wrapper wrapper); - List> selectValue(Map params,Wrapper wrapper); + /** + * 查询问卷调查的统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 统计值列表 + */ + List> selectValue(Map params, Wrapper wrapper); - List> selectTimeStatValue(Map params,Wrapper wrapper); + /** + * 查询问卷调查的时间统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 时间统计值列表 + */ + List> selectTimeStatValue(Map params, Wrapper wrapper); - List> selectGroup(Map params,Wrapper wrapper); - - - + /** + * 查询问卷调查的分组统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分组统计值列表 + */ + List> selectGroup(Map params, Wrapper wrapper); } - diff --git a/src/main/java/com/service/impl/ConfigServiceImpl.java b/src/main/java/com/service/impl/ConfigServiceImpl.java index 3005bf9..e7a1fdb 100644 --- a/src/main/java/com/service/impl/ConfigServiceImpl.java +++ b/src/main/java/com/service/impl/ConfigServiceImpl.java @@ -24,10 +24,10 @@ import com.utils.Query; public class ConfigServiceImpl extends ServiceImpl implements ConfigService { @Override public PageUtils queryPage(Map params, Wrapper wrapper) { + // 使用MyBatis-Plus的selectPage方法进行分页查询 Page page = this.selectPage( - new Query(params).getPage(), - wrapper + new Query(params).getPage(), // 获取分页参数 + wrapper // 查询条件 ); - return new PageUtils(page); - } + return new PageUtils(page); // 返回分页结果 } diff --git a/src/main/java/com/service/impl/ForumServiceImpl.java b/src/main/java/com/service/impl/ForumServiceImpl.java index e586ad4..a0da439 100644 --- a/src/main/java/com/service/impl/ForumServiceImpl.java +++ b/src/main/java/com/service/impl/ForumServiceImpl.java @@ -18,46 +18,76 @@ import com.service.ForumService; import com.entity.vo.ForumVO; import com.entity.view.ForumView; -@Service("forumService") +@Service("forumService") // 将该类标记为Spring的Service组件 public class ForumServiceImpl extends ServiceImpl implements ForumService { - + /** + * 查询分页数据 + * @param params 查询参数 + * @return 分页结果 + */ @Override public PageUtils queryPage(Map params) { + // 调用selectPage方法进行分页查询 Page page = this.selectPage( - new Query(params).getPage(), - new EntityWrapper() + new Query(params).getPage(), // 获取分页信息 + new EntityWrapper() // 创建查询条件 ); - return new PageUtils(page); + return new PageUtils(page); // 返回分页结果 } + /** + * 查询分页数据,带条件 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ @Override - public PageUtils queryPage(Map params, Wrapper wrapper) { - Page page =new Query(params).getPage(); - page.setRecords(baseMapper.selectListView(page,wrapper)); - PageUtils pageUtil = new PageUtils(page); - return pageUtil; - } + public PageUtils queryPage(Map params, Wrapper wrapper) { + // 创建分页对象 + Page page = new Query(params).getPage(); + // 设置记录 + page.setRecords(baseMapper.selectListView(page, wrapper)); + return new PageUtils(page); // 返回分页结果 + } + /** + * 查询VO列表 + * @param wrapper 查询条件包装器 + * @return VO对象列表 + */ @Override - public List selectListVO(Wrapper wrapper) { - return baseMapper.selectListVO(wrapper); - } - - @Override - public ForumVO selectVO(Wrapper wrapper) { - return baseMapper.selectVO(wrapper); - } - - @Override - public List selectListView(Wrapper wrapper) { - return baseMapper.selectListView(wrapper); - } - - @Override - public ForumView selectView(Wrapper wrapper) { - return baseMapper.selectView(wrapper); - } - + public List selectListVO(Wrapper wrapper) { + return baseMapper.selectListVO(wrapper); // 调用数据访问对象方法,返回VO对象列表 + } + + /** + * 查询单个VO对象 + * @param wrapper 查询条件包装器 + * @return 单个VO对象 + */ + @Override + public ForumVO selectVO(Wrapper wrapper) { + return baseMapper.selectVO(wrapper); // 调用数据访问对象方法,返回单个VO对象 + } + + /** + * 查询视图列表 + * @param wrapper 查询条件包装器 + * @return 视图对象列表 + */ + @Override + public List selectListView(Wrapper wrapper) { + return baseMapper.selectListView(wrapper); // 调用数据访问对象方法,返回视图对象列表 + } + /** + * 查询单个视图对象 + * @param wrapper 查询条件包装器 + * @return 单个视图对象 + */ + @Override + public ForumView selectView(Wrapper wrapper) { + return baseMapper.selectView(wrapper); // 调用数据访问对象方法,返回单个视图对象 + } } diff --git a/src/main/java/com/service/impl/LeixingServiceImpl.java b/src/main/java/com/service/impl/LeixingServiceImpl.java index bb98b59..c54972c 100644 --- a/src/main/java/com/service/impl/LeixingServiceImpl.java +++ b/src/main/java/com/service/impl/LeixingServiceImpl.java @@ -17,47 +17,75 @@ import com.entity.LeixingEntity; import com.service.LeixingService; import com.entity.vo.LeixingVO; import com.entity.view.LeixingView; - -@Service("leixingService") +@Service("leixingService") // 将该类标记为Spring的Service组件 public class LeixingServiceImpl extends ServiceImpl implements LeixingService { - + /** + * 查询分页数据 + * @param params 查询参数 + * @return 分页结果 + */ @Override public PageUtils queryPage(Map params) { + // 使用selectPage方法进行分页查询 Page page = this.selectPage( - new Query(params).getPage(), - new EntityWrapper() + new Query(params).getPage(), // 获取分页信息 + new EntityWrapper() // 创建查询条件 ); - return new PageUtils(page); + return new PageUtils(page); // 返回分页结果 } + /** + * 查询分页数据,带条件 + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分页结果 + */ @Override - public PageUtils queryPage(Map params, Wrapper wrapper) { - Page page =new Query(params).getPage(); - page.setRecords(baseMapper.selectListView(page,wrapper)); - PageUtils pageUtil = new PageUtils(page); - return pageUtil; - } + public PageUtils queryPage(Map params, Wrapper wrapper) { + // 创建分页对象 + Page page = new Query(params).getPage(); + // 设置记录 + page.setRecords(baseMapper.selectListView(page, wrapper)); + return new PageUtils(page); // 返回分页结果 + } + /** + * 查询VO列表 + * @param wrapper 查询条件包装器 + * @return VO对象列表 + */ @Override - public List selectListVO(Wrapper wrapper) { - return baseMapper.selectListVO(wrapper); - } - - @Override - public LeixingVO selectVO(Wrapper wrapper) { - return baseMapper.selectVO(wrapper); - } - - @Override - public List selectListView(Wrapper wrapper) { - return baseMapper.selectListView(wrapper); - } - - @Override - public LeixingView selectView(Wrapper wrapper) { - return baseMapper.selectView(wrapper); - } - + public List selectListVO(Wrapper wrapper) { + return baseMapper.selectListVO(wrapper); // 调用数据访问对象方法,返回VO对象列表 + } + + /** + * 查询单个VO对象 + * @param wrapper 查询条件包装器 + * @return 单个VO对象 + */ + @Override + public LeixingVO selectVO(Wrapper wrapper) { + return baseMapper.selectVO(wrapper); // 调用数据访问对象方法,返回单个VO对象 + } + + /** + * 查询视图列表 + * @param wrapper 查询条件包装器 + * @return 视图对象列表 + */ + @Override + public List selectListView(Wrapper wrapper) { + return baseMapper.selectListView(wrapper); // 调用数据访问对象方法,返回视图对象列表 + } -} + /** + * 查询单个视图对象 + * @param wrapper 查询条件包装器 + * @return 单个视图对象 + */ + @Override + public LeixingView selectView(Wrapper wrapper) { + return baseMapper.selectView(wrapper); // 调用数据访问对象方法,返回单个视图对象 + } diff --git a/src/main/java/com/service/impl/WenjuandiaochaServiceImpl.java b/src/main/java/com/service/impl/WenjuandiaochaServiceImpl.java index deb91f4..7063a05 100644 --- a/src/main/java/com/service/impl/WenjuandiaochaServiceImpl.java +++ b/src/main/java/com/service/impl/WenjuandiaochaServiceImpl.java @@ -11,19 +11,27 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.utils.PageUtils; import com.utils.Query; - import com.dao.WenjuandiaochaDao; import com.entity.WenjuandiaochaEntity; import com.service.WenjuandiaochaService; import com.entity.vo.WenjuandiaochaVO; -import com.entity.view.WenjuandiaochaView; +import com.entity.view.Wenjuandiaocha; +/** + * 问卷调查服务实现类 + * 继承自MyBatis-Plus的ServiceImpl,并实现WenjuandiaochaService接口 + */ @Service("wenjuandiaochaService") public class WenjuandiaochaServiceImpl extends ServiceImpl implements WenjuandiaochaService { - + /** + * 分页查询问卷调查数据 + * @param params 查询参数 + * @return 分页结果 + */ @Override public PageUtils queryPage(Map params) { + // 使用MyBatis-Plus的分页插件进行分页查询 Page page = this.selectPage( new Query(params).getPage(), new EntityWrapper() @@ -31,50 +39,93 @@ public class WenjuandiaochaServiceImpl extends ServiceImpl params, Wrapper wrapper) { - Page page =new Query(params).getPage(); - page.setRecords(baseMapper.selectListView(page,wrapper)); - PageUtils pageUtil = new PageUtils(page); - return pageUtil; + // 创建分页对象 + Page page = new Query(params).getPage(); + // 设置分页记录 + page.setRecords(baseMapper.selectListView(page, wrapper)); + // 返回分页工具类 + PageUtils pageUtil = new PageUtils(page); + return pageUtil; } + /** + * 查询问卷调查列表(带条件) + * @param wrapper 查询条件包装器 + * @return 问卷调查列表 + */ @Override public List selectListVO(Wrapper wrapper) { return baseMapper.selectListVO(wrapper); } + /** + * 查询单个问卷调查(带条件) + * @param wrapper 查询条件包装器 + * @return 单个问卷调查 + */ @Override public WenjuandiaochaVO selectVO(Wrapper wrapper) { return baseMapper.selectVO(wrapper); } + /** + * 查询问卷调查视图列表(带条件) + * @param wrapper 查询条件包装器 + * @return 问卷调查视图列表 + */ @Override public List selectListView(Wrapper wrapper) { return baseMapper.selectListView(wrapper); } + /** + * 查询单个问卷调查视图(带条件) + * @param wrapper 查询条件包装器 + * @return 单个问卷调查视图 + */ @Override public WenjuandiaochaView selectView(Wrapper wrapper) { return baseMapper.selectView(wrapper); } + /** + * 查询问卷调查的统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 统计值列表 + */ @Override public List> selectValue(Map params, Wrapper wrapper) { return baseMapper.selectValue(params, wrapper); } + /** + * 查询问卷调查的时间统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 时间统计值列表 + */ @Override public List> selectTimeStatValue(Map params, Wrapper wrapper) { return baseMapper.selectTimeStatValue(params, wrapper); } + /** + * 查询问卷调查的分组统计值(带条件) + * @param params 查询参数 + * @param wrapper 查询条件包装器 + * @return 分组统计值列表 + */ @Override public List> selectGroup(Map params, Wrapper wrapper) { return baseMapper.selectGroup(params, wrapper); } - - - - } diff --git a/src/main/java/com/utils/FileUtil.java b/src/main/java/com/utils/FileUtil.java index d581324..248078b 100644 --- a/src/main/java/com/utils/FileUtil.java +++ b/src/main/java/com/utils/FileUtil.java @@ -1,7 +1,7 @@ package com.utils; import java.io.ByteArrayOutputStream; -import java.io.File; +import java.io.File;// 导入File类 import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -11,17 +11,26 @@ import java.io.InputStream; */ public class FileUtil { - public static byte[] FileToByte(File file) throws IOException { - // 将数据转为流 - @SuppressWarnings("resource") - InputStream content = new FileInputStream(file); - ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); - byte[] buff = new byte[100]; - int rc = 0; - while ((rc = content.read(buff, 0, 100)) > 0) { - swapStream.write(buff, 0, rc); - } - // 获得二进制数组 - return swapStream.toByteArray(); - } + + /** + * 将文件转换为字节数组 + * @param file + * @return + * @throws IOException 可能抛出输入输出异常 + */ + public static byte[] FileToByte(File file) throws IOException { + // 将文件数据转为输入流 + @SuppressWarnings("resource") // 这个资源在方法末尾会自动关闭,抑制编译警告 + InputStream content = new FileInputStream(file); // 创建FileInputStream对象读取文件 + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); // 创建字节数组输出流对象 + byte[] buff = new byte[100]; + int rc = 0; + + // 循环读取文件数据,直到文件结束 + while ((rc = content.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); // 将读取的数据写入字节数组输出流 + } + + return swapStream.toByteArray(); + } }