hujiali_branch
hjl 8 months ago
parent 1e85e38192
commit 8945f4a85a

@ -1,7 +1,5 @@
package com.controller; package com.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
@ -14,10 +12,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.annotation.IgnoreAuth; import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper; // MyBatis-Plus的实体包装器
import com.entity.ConfigEntity; import com.entity.ConfigEntity; // 配置实体类
import com.service.ConfigService; import com.service.ConfigService; // 配置服务类
import com.utils.MPUtil; import com.utils.MPUtil; // MyBatis-Plus工具类
import com.utils.PageUtils; import com.utils.PageUtils;
import com.utils.R; import com.utils.R;
import com.utils.ValidatorUtils; import com.utils.ValidatorUtils;
@ -25,88 +23,106 @@ import com.utils.ValidatorUtils;
/** /**
* *
*/ */
@RequestMapping("config") @RequestMapping("config") // 设置基本请求路径为"/config"
@RestController @RestController // 标记为REST风格的控制器
public class ConfigController{ public class ConfigController {
@Autowired @Autowired // 自动注入ConfigService
private ConfigService configService; private ConfigService configService;
/** /**
* *
* @param params
* @param config
* @return
*/ */
@RequestMapping("/page") @RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ConfigEntity config){ public R page(@RequestParam Map<String, Object> params, ConfigEntity config) {
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); // 创建EntityWrapper用于条件构造
PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param params
* @param config
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/list") @RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ConfigEntity config){ public R list(@RequestParam Map<String, Object> params, ConfigEntity config) {
EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); EntityWrapper<ConfigEntity> ew = new EntityWrapper<ConfigEntity>(); // 创建EntityWrapper用于条件构造
PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); PageUtils page = configService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, config), params), params)); // 查询分页数据
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param id ID
* @return ID
*/ */
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}") // 用于获取指定ID的配置信息
public R info(@PathVariable("id") String id){ public R info(@PathVariable("id") String id) {
ConfigEntity config = configService.selectById(id); ConfigEntity config = configService.selectById(id); // 根据ID查询配置
return R.ok().put("data", config); return R.ok().put("data", config);
} }
/** /**
* *
* @param id ID
* @return ID
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}") // 用于获取指定ID的配置信息详情
public R detail(@PathVariable("id") String id){ public R detail(@PathVariable("id") String id) {
ConfigEntity config = configService.selectById(id); ConfigEntity config = configService.selectById(id); // 根据ID查询配置
return R.ok().put("data", config); return R.ok().put("data", config);
} }
/** /**
* name * name
* @param name
* @return
*/ */
@RequestMapping("/info") @RequestMapping("/info") // 用于根据名称获取配置信息
public R infoByName(@RequestParam String name){ public R infoByName(@RequestParam String name) {
ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile")); ConfigEntity config = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile")); // 根据名称查询配置
return R.ok().put("data", config); return R.ok().put("data", config);
} }
/** /**
* *
* @param config
* @return
*/ */
@PostMapping("/save") @PostMapping("/save") // 用于保存配置
public R save(@RequestBody ConfigEntity config){ public R save(@RequestBody ConfigEntity config) {
// ValidatorUtils.validateEntity(config); // ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用)
configService.insert(config); configService.insert(config); // 保存配置
return R.ok(); return R.ok();
} }
/** /**
* *
* @param config
* @return
*/ */
@RequestMapping("/update") @RequestMapping("/update") // 用于修改配置
public R update(@RequestBody ConfigEntity config){ public R update(@RequestBody ConfigEntity config) {
// ValidatorUtils.validateEntity(config); // ValidatorUtils.validateEntity(config); // 验证配置实体(注释掉此行可以在需要时启用)
configService.updateById(config);//全部更新 configService.updateById(config); // 根据ID更新配置
return R.ok(); return R.ok();
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@RequestMapping("/delete") @RequestMapping("/delete") // 用于删除配置
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids) {
configService.deleteBatchIds(Arrays.asList(ids)); configService.deleteBatchIds(Arrays.asList(ids)); // 批量删除配置
return R.ok(); return R.ok();
} }
} }

@ -10,14 +10,14 @@ 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.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的依赖注入注解
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController; // 导入Spring的REST控制器注解
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile; // 导入Spring的文件上传接口
import com.annotation.IgnoreAuth; import com.annotation.IgnoreAuth; // 导入自定义注解,表示忽略身份验证
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper用于构建查询条件
import com.entity.ConfigEntity; import com.entity.ConfigEntity;
import com.entity.EIException; import com.entity.EIException;
import com.service.ConfigService; import com.service.ConfigService;
@ -26,65 +26,84 @@ import com.utils.R;
/** /**
* *
*/ */
@RestController @RestController // 标记该类为REST控制器
@RequestMapping("file") @RequestMapping("file") // 设置基本请求路径为"/file"
@SuppressWarnings({"unchecked","rawtypes"}) @SuppressWarnings({"unchecked","rawtypes"}) // 忽略编译警告
public class FileController{ public class FileController {
@Autowired
@Autowired // 自动注入ConfigService服务
private ConfigService configService; private ConfigService configService;
/** /**
* *
* @param file
* @param type
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/upload") @RequestMapping("/upload") // 映射请求路径为"/upload"
@IgnoreAuth @IgnoreAuth // 忽略身份验证
public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception { public R upload(@RequestParam("file") MultipartFile file, String type, HttpServletRequest request) throws Exception {
// 检查上传的文件是否为空
if (file.isEmpty()) { if (file.isEmpty()) {
throw new EIException("上传文件不能为空"); throw new EIException("上传文件不能为空");
} }
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1); // 获取文件扩展名
String fileName = new Date().getTime()+"."+fileExt; String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName); String fileName = new Date().getTime() + "." + fileExt;
// 定义文件保存的目标路径
File dest = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + fileName);
file.transferTo(dest); file.transferTo(dest);
/** /**
* 使ideaeclipse * 使IDEAEclipse
* "D:\\ssmpiv99\\src\\main\\webapp\\upload"upload *
* * "D:\\ssmpiv99\\src\\main\\webapp\\upload"upload
*
*/ */
//FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/ // FileUtils.copyFile(dest, new File("D:\\ssmpiv99\\src\\main\\webapp\\upload" + "/" + fileName)); /** 修改了路径后请将该行最前面的//注释去掉 **/
if(StringUtils.isNotBlank(type) && type.equals("1")) {
// 如果type不为空且等于"1",则更新或保存配置信息
if (StringUtils.isNotBlank(type) && type.equals("1")) {
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile")); ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
if(configEntity==null) { if (configEntity == null) {
configEntity = new ConfigEntity(); configEntity = new ConfigEntity(); // 创建新的配置实体
configEntity.setName("faceFile"); configEntity.setName("faceFile");
configEntity.setValue(fileName); configEntity.setValue(fileName);
} else { } else {
configEntity.setValue(fileName); configEntity.setValue(fileName);
} }
configService.insertOrUpdate(configEntity); configService.insertOrUpdate(configEntity); // 保存或更新配置
} }
return R.ok().put("file", fileName); return R.ok().put("file", fileName); // 返回上传结果,包含文件名
} }
/** /**
* *
* @param fileName
* @param request HttpServletRequest
* @param response HttpServletResponse
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/download") @RequestMapping("/download") // 映射请求路径为"/download"
public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) { public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
try { try {
File file = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName); // 定义文件的完整路径
File file = new File(request.getSession().getServletContext().getRealPath("/upload") + "/" + fileName);
// 检查文件是否存在
if (file.exists()) { if (file.exists()) {
response.reset(); response.reset(); // 重置响应
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+"\""); // 设置响应头,指示文件下载
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "no-cache");
response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Credentials", "true");
response.setContentType("application/octet-stream; charset=UTF-8"); response.setContentType("application/octet-stream; charset=UTF-8"); // 设置内容类型
// 将文件内容写入响应输出流
IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream()); IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace(); // 打印异常信息
} }
} }
} }

@ -2,41 +2,41 @@ package com.controller;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.text.ParseException; import java.text.ParseException; // 导入解析异常
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays; // 导入Arrays工具类
import java.util.Calendar; import java.util.Calendar;
import java.util.Map; import java.util.Map; // 导入Map接口
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator; // 导入迭代器接口
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest; // 导入Servlet请求类
import java.io.IOException; import java.io.IOException;
import com.utils.ValidatorUtils; import com.utils.ValidatorUtils; // 导入验证工具类
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang的StringUtils类用于字符串操作
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的依赖注入注解
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable; // 导入路径变量注解
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody; // 导入请求体注解
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController; // 导入REST控制器注解
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth; import com.annotation.IgnoreAuth;
import com.entity.ForumEntity; import com.entity.ForumEntity; // 导入论坛实体类
import com.entity.view.ForumView; import com.entity.view.ForumView; // 导入论坛视图类
import com.service.ForumService; import com.service.ForumService; // 导入论坛服务类
import com.service.TokenService; import com.service.TokenService;
import com.utils.PageUtils; import com.utils.PageUtils; // 导入分页工具类
import com.utils.R; import com.utils.R;
import com.utils.MD5Util; import com.utils.MD5Util;
import com.utils.MPUtil; import com.utils.MPUtil; // 导入MyBatis-Plus工具类
import com.utils.CommonUtil; import com.utils.CommonUtil;
/** /**
@ -46,217 +46,238 @@ import com.utils.CommonUtil;
* @email * @email
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
@RestController @RestController // 标记该类为REST控制器
@RequestMapping("/forum") @RequestMapping("/forum")
public class ForumController { public class ForumController {
@Autowired @Autowired
private ForumService forumService; private ForumService forumService; // 注入论坛服务
/** /**
* *
* @param params
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/page") @RequestMapping("/page") // 映射请求路径为"/page"
public R page(@RequestParam Map<String, Object> params,ForumEntity forum, public R page(@RequestParam Map<String, Object> params, ForumEntity forum, HttpServletRequest request) {
HttpServletRequest request){ // 如果当前用户不是管理员则设置用户ID
if(!request.getSession().getAttribute("role").toString().equals("管理员")) { if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId")); forum.setUserid((Long) request.getSession().getAttribute("userId"));
} }
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>(); EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
// 查询论坛列表分页数据
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
request.setAttribute("data", page); request.setAttribute("data", page); // 将数据设置到请求属性中
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param params
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/list") @RequestMapping("/list") // 映射请求路径为"/list"
public R list(@RequestParam Map<String, Object> params,ForumEntity forum, public R list(@RequestParam Map<String, Object> params, ForumEntity forum, HttpServletRequest request) {
HttpServletRequest request){ // 如果当前用户不是管理员则设置用户ID
if(!request.getSession().getAttribute("role").toString().equals("管理员")) { if (!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId")); forum.setUserid((Long) request.getSession().getAttribute("userId"));
} }
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>(); EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
// 查询论坛列表分页数据
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
request.setAttribute("data", page); request.setAttribute("data", page); // 将数据设置到请求属性中
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* * 访
* @param params
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/flist") @RequestMapping("/flist") // 映射请求路径为"/flist"
public R flist(@RequestParam Map<String, Object> params,ForumEntity forum, HttpServletRequest request){ public R flist(@RequestParam Map<String, Object> params, ForumEntity forum, HttpServletRequest request) {
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>(); EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
// 查询论坛列表分页数据
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params)); PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param forum
* @return
*/ */
@RequestMapping("/query") @RequestMapping("/query") // 映射请求路径为"/query"
public R query(ForumEntity forum){ public R query(ForumEntity forum) {
EntityWrapper< ForumEntity> ew = new EntityWrapper< ForumEntity>(); EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
ew.allEq(MPUtil.allEQMapPre( forum, "forum")); ew.allEq(MPUtil.allEQMapPre(forum, "forum")); // 构建查询条件
ForumView forumView = forumService.selectView(ew); ForumView forumView = forumService.selectView(ew); // 查询论坛视图
return R.ok("查询论坛表成功").put("data", forumView); return R.ok("查询论坛表成功").put("data", forumView);
} }
/** /**
* *
* @param id ID
* @return
*/ */
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}") // 映射请求路径为"/info/{id}"
public R info(@PathVariable("id") Long id){ public R info(@PathVariable("id") Long id) {
ForumEntity forum = forumService.selectById(id); ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛
return R.ok().put("data", forum); return R.ok().put("data", forum);
} }
/** /**
* *
* @param id ID
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}") // 映射请求路径为"/detail/{id}"
public R detail(@PathVariable("id") Long id){ public R detail(@PathVariable("id") Long id) {
ForumEntity forum = forumService.selectById(id); ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛
return R.ok().put("data", forum); return R.ok().put("data", forum);
} }
/** /**
* *
* @param id ID
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/list/{id}") @RequestMapping("/list/{id}") // 映射请求路径为"/list/{id}"
public R list(@PathVariable("id") String id){ public R list(@PathVariable("id") String id) {
ForumEntity forum = forumService.selectById(id); ForumEntity forum = forumService.selectById(id); // 根据ID查询论坛
getChilds(forum); getChilds(forum); // 获取子项
return R.ok().put("data", forum); return R.ok().put("data", forum); // 返回论坛信息及子项
} }
/**
*
* @param forum
* @return
*/
private ForumEntity getChilds(ForumEntity forum) { private ForumEntity getChilds(ForumEntity forum) {
List<ForumEntity> childs = new ArrayList<ForumEntity>(); List<ForumEntity> childs = new ArrayList<ForumEntity>();
childs = forumService.selectList(new EntityWrapper<ForumEntity>().eq("parentid", forum.getId())); childs = forumService.selectList(new EntityWrapper<ForumEntity>().eq("parentid", forum.getId())); // 根据父ID查询子项
if(childs == null || childs.size()==0) { if (childs == null || childs.size() == 0) {
return null; return null; // 如果没有子项则返回null
} }
forum.setChilds(childs); forum.setChilds(childs); // 设置子项
for(ForumEntity forumEntity : childs) { for (ForumEntity forumEntity : childs) {
getChilds(forumEntity); getChilds(forumEntity); // 递归获取每个子项的子项
} }
return forum; return forum; // 返回具有子项的论坛
} }
/** /**
* *
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/save") @RequestMapping("/save") // 映射请求路径为"/save"
public R save(@RequestBody ForumEntity forum, HttpServletRequest request){ public R save(@RequestBody ForumEntity forum, HttpServletRequest request) {
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
//ValidatorUtils.validateEntity(forum); // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用)
forum.setUserid((Long)request.getSession().getAttribute("userId")); forum.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID
forumService.insert(forum); // 保存论坛信息
forumService.insert(forum);
return R.ok(); return R.ok();
} }
/** /**
* *
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/add") @RequestMapping("/add") // 映射请求路径为"/add"
public R add(@RequestBody ForumEntity forum, HttpServletRequest request){ public R add(@RequestBody ForumEntity forum, HttpServletRequest request) {
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); forum.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
//ValidatorUtils.validateEntity(forum); // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用)
forum.setUserid((Long)request.getSession().getAttribute("userId")); forum.setUserid((Long) request.getSession().getAttribute("userId")); // 设置用户ID
forumService.insert(forum); // 保存论坛信息
forumService.insert(forum);
return R.ok(); return R.ok();
} }
/** /**
* *
* @param forum
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/update") @RequestMapping("/update") // 映射请求路径为"/update"
@Transactional @Transactional // 开启事务
public R update(@RequestBody ForumEntity forum, HttpServletRequest request){ public R update(@RequestBody ForumEntity forum, HttpServletRequest request) {
//ValidatorUtils.validateEntity(forum); // ValidatorUtils.validateEntity(forum); // 验证实体(可选择启用)
forumService.updateById(forum);//全部更新 forumService.updateById(forum); // 更新论坛信息
return R.ok(); return R.ok();
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@RequestMapping("/delete") @RequestMapping("/delete") // 映射请求路径为"/delete"
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids) {
forumService.deleteBatchIds(Arrays.asList(ids)); forumService.deleteBatchIds(Arrays.asList(ids)); // 批量删除论坛
return R.ok(); return R.ok();
} }
/** /**
* *
* @param columnName
* @param type
* @param map
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/remind/{columnName}/{type}") @RequestMapping("/remind/{columnName}/{type}") // 映射请求路径为"/remind/{columnName}/{type}"
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) { @PathVariable("type") String type, @RequestParam Map<String, Object> map) {
map.put("column", columnName); map.put("column", columnName); // 将列名放入请求参数
map.put("type", type); map.put("type", type); // 将类型放入请求参数
if(type.equals("2")) { // 如果类型为2进行日期提醒处理
if (type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
Date remindStartDate = null; Date remindStartDate = null;
Date remindEndDate = null; Date remindEndDate = null;
if(map.get("remindstart")!=null) { if (map.get("remindstart") != null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart); c.add(Calendar.DAY_OF_MONTH, remindStart); // 加上提醒天数
remindStartDate = c.getTime(); remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate)); map.put("remindstart", sdf.format(remindStartDate)); // 格式化日期并放入请求参数
} }
if(map.get("remindend")!=null) { if (map.get("remindend") != null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd); c.add(Calendar.DAY_OF_MONTH, remindEnd); // 加上提醒天数
remindEndDate = c.getTime(); remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate)); map.put("remindend", sdf.format(remindEndDate)); // 格式化日期并放入请求参数
} }
} }
// 构建查询条件
Wrapper<ForumEntity> wrapper = new EntityWrapper<ForumEntity>(); Wrapper<ForumEntity> wrapper = new EntityWrapper<ForumEntity>();
if(map.get("remindstart")!=null) { if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart")); wrapper.ge(columnName, map.get("remindstart")); // 大于等于开始日期
} }
if(map.get("remindend")!=null) { if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend")); wrapper.le(columnName, map.get("remindend")); // 小于等于结束日期
} }
int count = forumService.selectCount(wrapper); // 查询数量
int count = forumService.selectCount(wrapper); return R.ok().put("count", count); // 返回数量
return R.ok().put("count", count);
} }
} }

@ -1,6 +1,6 @@
package com.controller; package com.controller;
import java.math.BigDecimal; import java.math.BigDecimal; // 导入BigDecimal以处理高精度数值
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
@ -8,35 +8,35 @@ import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator; // 导入迭代器接口
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List; // 导入List接口
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import com.utils.ValidatorUtils; import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils; // 导入Apache Commons Lang的字符串处理类
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam; // 导入请求参数注解
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper; // 导入MyBatis-Plus的EntityWrapper用于构建查询条件
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper; // 导入MyBatis-Plus的Wrapper接口
import com.annotation.IgnoreAuth; import com.annotation.IgnoreAuth;
import com.entity.LeixingEntity; import com.entity.LeixingEntity;
import com.entity.view.LeixingView; import com.entity.view.LeixingView; // 导入类型视图类
import com.service.LeixingService; import com.service.LeixingService; // 导入类型服务类
import com.service.TokenService; import com.service.TokenService;
import com.utils.PageUtils; import com.utils.PageUtils; // 导入分页工具类
import com.utils.R; import com.utils.R; // 导入响应工具类
import com.utils.MD5Util; import com.utils.MD5Util;
import com.utils.MPUtil; import com.utils.MPUtil; // 导入MyBatis-Plus工具类
import com.utils.CommonUtil; import com.utils.CommonUtil;
/** /**
@ -46,185 +46,201 @@ import com.utils.CommonUtil;
* @email * @email
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
@RestController @RestController // 标记该类为REST控制器
@RequestMapping("/leixing") @RequestMapping("/leixing") // 设置基本请求路径为"/leixing"
public class LeixingController { public class LeixingController {
@Autowired @Autowired
private LeixingService leixingService; private LeixingService leixingService; // 自动注入类型服务
/** /**
* *
* @param params
* @param leixing
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/page") @RequestMapping("/page") // 映射请求路径为"/page"
public R page(@RequestParam Map<String, Object> params,LeixingEntity leixing, public R page(@RequestParam Map<String, Object> params, LeixingEntity leixing,
HttpServletRequest request){ HttpServletRequest request) {
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
// 查询分页数据
PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params));
request.setAttribute("data", page); request.setAttribute("data", page); // 将数据设置到请求属性中
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param params
* @param leixing
* @param request HttpServletRequest
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/list") @RequestMapping("/list") // 映射请求路径为"/list"
public R list(@RequestParam Map<String, Object> params,LeixingEntity leixing, public R list(@RequestParam Map<String, Object> params, LeixingEntity leixing,
HttpServletRequest request){ HttpServletRequest request) {
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
// 查询分页数据
PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params)); PageUtils page = leixingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, leixing), params), params));
request.setAttribute("data", page); request.setAttribute("data", page); // 将数据设置到请求属性中
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
* @param leixing
* @return
*/ */
@RequestMapping("/lists") @RequestMapping("/lists") // 映射请求路径为"/lists"
public R list( LeixingEntity leixing){ public R list(LeixingEntity leixing) {
EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
ew.allEq(MPUtil.allEQMapPre( leixing, "leixing")); ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件
return R.ok().put("data", leixingService.selectListView(ew)); return R.ok().put("data", leixingService.selectListView(ew));
} }
/** /**
* *
* @param leixing
* @return
*/ */
@RequestMapping("/query") @RequestMapping("/query") // 映射请求路径为"/query"
public R query(LeixingEntity leixing){ public R query(LeixingEntity leixing) {
EntityWrapper< LeixingEntity> ew = new EntityWrapper< LeixingEntity>(); EntityWrapper<LeixingEntity> ew = new EntityWrapper<LeixingEntity>(); // 创建查询条件
ew.allEq(MPUtil.allEQMapPre( leixing, "leixing")); ew.allEq(MPUtil.allEQMapPre(leixing, "leixing")); // 设置查询条件
LeixingView leixingView = leixingService.selectView(ew); LeixingView leixingView = leixingService.selectView(ew); // 查询类型视图
return R.ok("查询类型成功").put("data", leixingView); return R.ok("查询类型成功").put("data", leixingView);
} }
/** /**
* *
* @param id ID
* @return
*/ */
@RequestMapping("/info/{id}") @RequestMapping("/info/{id}") // 映射请求路径为"/info/{id}"
public R info(@PathVariable("id") Long id){ public R info(@PathVariable("id") Long id) {
LeixingEntity leixing = leixingService.selectById(id); LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型
return R.ok().put("data", leixing); return R.ok().put("data", leixing);
} }
/** /**
* *
* @param id ID
* @return
*/ */
@IgnoreAuth @IgnoreAuth // 忽略身份验证
@RequestMapping("/detail/{id}") @RequestMapping("/detail/{id}") // 映射请求路径为"/detail/{id}"
public R detail(@PathVariable("id") Long id){ public R detail(@PathVariable("id") Long id) {
LeixingEntity leixing = leixingService.selectById(id); LeixingEntity leixing = leixingService.selectById(id); // 根据ID查询类型
return R.ok().put("data", leixing); return R.ok().put("data", leixing);
} }
/** /**
* *
* @param leixing
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/save") @RequestMapping("/save") // 映射请求路径为"/save"
public R save(@RequestBody LeixingEntity leixing, HttpServletRequest request){ public R save(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
leixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
//ValidatorUtils.validateEntity(leixing); // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
leixingService.insert(leixing); leixingService.insert(leixing); // 保存类型信息
return R.ok(); return R.ok();
} }
/** /**
* *
* @param leixing
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/add") @RequestMapping("/add") // 映射请求路径为"/add"
public R add(@RequestBody LeixingEntity leixing, HttpServletRequest request){ public R add(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
leixing.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); leixing.setId(new Date().getTime() + new Double(Math.floor(Math.random() * 1000)).longValue()); // 生成唯一ID
//ValidatorUtils.validateEntity(leixing); // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
leixingService.insert(leixing); leixingService.insert(leixing); // 保存类型信息
return R.ok(); return R.ok();
} }
/** /**
* *
* @param leixing
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/update") @RequestMapping("/update") // 映射请求路径为"/update"
@Transactional @Transactional // 开启事务
public R update(@RequestBody LeixingEntity leixing, HttpServletRequest request){ public R update(@RequestBody LeixingEntity leixing, HttpServletRequest request) {
//ValidatorUtils.validateEntity(leixing); // ValidatorUtils.validateEntity(leixing); // 验证实体(可选择启用)
leixingService.updateById(leixing);//全部更新 leixingService.updateById(leixing); // 更新类型信息
return R.ok(); return R.ok();
} }
/** /**
* *
* @param ids ID
* @return
*/ */
@RequestMapping("/delete") @RequestMapping("/delete") // 映射请求路径为"/delete"
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids) {
leixingService.deleteBatchIds(Arrays.asList(ids)); leixingService.deleteBatchIds(Arrays.asList(ids)); // 批量删除类型
return R.ok(); return R.ok();
} }
/** /**
* *
* @param columnName
* @param type
* @param map
* @param request HttpServletRequest
* @return
*/ */
@RequestMapping("/remind/{columnName}/{type}") @RequestMapping("/remind/{columnName}/{type}") // 映射请求路径为"/remind/{columnName}/{type}"
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) { @PathVariable("type") String type, @RequestParam Map<String, Object> map) {
map.put("column", columnName); map.put("column", columnName); // 将列名放入请求参数
map.put("type", type); map.put("type", type); // 将类型放入请求参数
if(type.equals("2")) { // 如果类型为2进行日期提醒处理
if (type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
Date remindStartDate = null; Date remindStartDate = null;
Date remindEndDate = null; Date remindEndDate = null;
if(map.get("remindstart")!=null) { // 处理提醒开始时间
if (map.get("remindstart") != null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart); c.add(Calendar.DAY_OF_MONTH, remindStart); // 添加提醒天数
remindStartDate = c.getTime(); remindStartDate = c.getTime(); // 获取新的开始日期
map.put("remindstart", sdf.format(remindStartDate)); map.put("remindstart", sdf.format(remindStartDate)); // 格式化并放入请求参数
} }
if(map.get("remindend")!=null) { // 处理提醒结束时间
if (map.get("remindend") != null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd); c.add(Calendar.DAY_OF_MONTH, remindEnd); // 添加提醒天数
remindEndDate = c.getTime(); remindEndDate = c.getTime(); // 获取新的结束日期
map.put("remindend", sdf.format(remindEndDate)); map.put("remindend", sdf.format(remindEndDate)); // 格式化并放入请求参数
} }
} }
// 构建查询条件
Wrapper<LeixingEntity> wrapper = new EntityWrapper<LeixingEntity>(); Wrapper<LeixingEntity> wrapper = new EntityWrapper<LeixingEntity>();
if(map.get("remindstart")!=null) { if (map.get("remindstart") != null) {
wrapper.ge(columnName, map.get("remindstart")); wrapper.ge(columnName, map.get("remindstart")); // 大于等于开始日期
} }
if(map.get("remindend")!=null) { if (map.get("remindend") != null) {
wrapper.le(columnName, map.get("remindend")); wrapper.le(columnName, map.get("remindend")); // 小于等于结束日期
} }
int count = leixingService.selectCount(wrapper); // 查询数量
int count = leixingService.selectCount(wrapper); return R.ok().put("count", count); // 返回数量
return R.ok().put("count", count);
} }
} }

@ -1,12 +1,15 @@
package com.dao; package com.dao;
import com.baomidou.mybatisplus.mapper.BaseMapper; import com.baomidou.mybatisplus.mapper.BaseMapper; // 导入MyBatis-Plus的BaseMapper接口
import com.entity.ConfigEntity; import com.entity.ConfigEntity; // 导入配置实体类
/** /**
* * DAO
* 访ConfigEntity
*/ */
public interface ConfigDao extends BaseMapper<ConfigEntity> { public interface ConfigDao extends BaseMapper<ConfigEntity> {
// ConfigDao接口继承了BaseMapper接口意味着它自动获得了CRUD方法
// 可以根据需要在此处添加自定义的方法
} }

@ -1,19 +1,19 @@
package com.dao; package com.dao;
import com.entity.ForumEntity; import com.entity.ForumEntity; // 导入论坛实体类
import com.baomidou.mybatisplus.mapper.BaseMapper; import com.baomidou.mybatisplus.mapper.BaseMapper; // 导入MyBatis-Plus的BaseMapper接口
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.mapper.Wrapper; 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 org.apache.ibatis.annotations.Param;
import com.entity.vo.ForumVO; import com.entity.vo.ForumVO; // 导入论坛VO类
import com.entity.view.ForumView; import com.entity.view.ForumView; // 导入论坛视图类
/** /**
* * DAO
* 访ForumEntity
* *
* @author * @author
* @email * @email
@ -21,15 +21,39 @@ import com.entity.view.ForumView;
*/ */
public interface ForumDao extends BaseMapper<ForumEntity> { public interface ForumDao extends BaseMapper<ForumEntity> {
/**
* VO
* @param wrapper
* @return VO
*/
List<ForumVO> selectListVO(@Param("ew") Wrapper<ForumEntity> wrapper); List<ForumVO> selectListVO(@Param("ew") Wrapper<ForumEntity> wrapper);
/**
* VO
* @param wrapper
* @return VO
*/
ForumVO selectVO(@Param("ew") Wrapper<ForumEntity> wrapper); ForumVO selectVO(@Param("ew") Wrapper<ForumEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
List<ForumView> selectListView(@Param("ew") Wrapper<ForumEntity> wrapper); List<ForumView> selectListView(@Param("ew") Wrapper<ForumEntity> wrapper);
List<ForumView> selectListView(Pagination page,@Param("ew") Wrapper<ForumEntity> wrapper); /**
*
* @param page
* @param wrapper
* @return
*/
List<ForumView> selectListView(Pagination page, @Param("ew") Wrapper<ForumEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
ForumView selectView(@Param("ew") Wrapper<ForumEntity> wrapper); ForumView selectView(@Param("ew") Wrapper<ForumEntity> wrapper);
} }

@ -8,12 +8,12 @@ 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 org.apache.ibatis.annotations.Param;
import com.entity.vo.LeixingVO; import com.entity.vo.LeixingVO; // 导入类型VO类
import com.entity.view.LeixingView; import com.entity.view.LeixingView;
/** /**
* * DAO
* LeixingEntity
* *
* @author * @author
* @email * @email
@ -21,15 +21,39 @@ import com.entity.view.LeixingView;
*/ */
public interface LeixingDao extends BaseMapper<LeixingEntity> { public interface LeixingDao extends BaseMapper<LeixingEntity> {
/**
* VO
* @param wrapper
* @return VO
*/
List<LeixingVO> selectListVO(@Param("ew") Wrapper<LeixingEntity> wrapper); List<LeixingVO> selectListVO(@Param("ew") Wrapper<LeixingEntity> wrapper);
/**
* VO
* @param wrapper
* @return VO
*/
LeixingVO selectVO(@Param("ew") Wrapper<LeixingEntity> wrapper); LeixingVO selectVO(@Param("ew") Wrapper<LeixingEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
List<LeixingView> selectListView(@Param("ew") Wrapper<LeixingEntity> wrapper); List<LeixingView> selectListView(@Param("ew") Wrapper<LeixingEntity> wrapper);
List<LeixingView> selectListView(Pagination page,@Param("ew") Wrapper<LeixingEntity> wrapper); /**
*
* @param page
* @param wrapper
* @return
*/
List<LeixingView> selectListView(Pagination page, @Param("ew") Wrapper<LeixingEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
LeixingView selectView(@Param("ew") Wrapper<LeixingEntity> wrapper); LeixingView selectView(@Param("ew") Wrapper<LeixingEntity> wrapper);
} }

@ -9,25 +9,25 @@ import com.baomidou.mybatisplus.enums.IdType;
/** /**
* : * :
*/ */
@TableName("config") @TableName("config")// 指定该类对应的数据库表名为"config"
public class ConfigEntity implements Serializable{ public class ConfigEntity implements Serializable{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO) // 主键ID使用自增长方式
private Long id; private Long id;
/** /**
* key *
*/ */
private String name; private String name;
/** /**
* value *
*/ */
private String value; private String value;
public Long getId() { public Long getId() {
return id; return id; // 返回配置ID
} }
public void setId(Long id) { public void setId(Long id) {
@ -39,7 +39,7 @@ private static final long serialVersionUID = 1L;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;//设置配置名称
} }
public String getValue() { public String getValue() {
@ -47,7 +47,7 @@ private static final long serialVersionUID = 1L;
} }
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;// 设置配置值
} }
} }

@ -16,6 +16,8 @@ import java.util.List;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.poi.ss.formula.functions.T;
import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.enums.FieldFill; import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.enums.IdType;
@ -37,14 +39,15 @@ public class ForumEntity<T> implements Serializable {
} }
// 接收ForumEntity对象的构造函数
public ForumEntity(T t) { public ForumEntity(T t) {
try { try {
// 复制属性,将传入对象的属性复制到当前对象
BeanUtils.copyProperties(this, t); BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block // 异常处理,打印堆栈信息
e.printStackTrace(); e.printStackTrace();
} }
}
/** /**
* id * id
@ -99,10 +102,10 @@ public class ForumEntity<T> implements Serializable {
private Date addtime; private Date addtime;
public Date getAddtime() { public Date getAddtime() {
return addtime; return addtime;// 返回添加时间
} }
public void setAddtime(Date addtime) { public void setAddtime(Date addtime) {
this.addtime = addtime; this.addtime = addtime;// 设置添加时间
} }
public Long getId() { public Long getId() {
@ -110,9 +113,12 @@ public class ForumEntity<T> implements Serializable {
} }
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;// 设置帖子ID
} }
@TableField(exist = false) /**
*
*/
@TableField(exist = false) // 该字段不在数据库表中存在
private List<ForumEntity> childs; private List<ForumEntity> childs;
public List<ForumEntity> getChilds() { public List<ForumEntity> getChilds() {
@ -120,7 +126,7 @@ public class ForumEntity<T> implements Serializable {
} }
public void setChilds(List<ForumEntity> childs) { public void setChilds(List<ForumEntity> childs) {
this.childs = childs; this.childs = childs;// 设置子帖子
} }
/** /**
* *

@ -16,6 +16,8 @@ import java.util.List;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.apache.poi.ss.formula.functions.T;
import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.enums.FieldFill; import com.baomidou.mybatisplus.enums.FieldFill;
import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.enums.IdType;
@ -37,11 +39,13 @@ public class LeixingEntity<T> implements Serializable {
} }
// 接收LeixingEntity对象的构造函数
public LeixingEntity(T t) { public LeixingEntity(T t) {
try { try {
// 复制属性,将传入对象的属性复制到当前对象
BeanUtils.copyProperties(this, t); BeanUtils.copyProperties(this, t);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block // 异常处理,打印堆栈信息
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -58,15 +62,15 @@ public class LeixingEntity<T> implements Serializable {
private String leixing; private String leixing;
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")// 指定JSON格式化
@DateTimeFormat @DateTimeFormat// 用于Spring格式化
private Date addtime; private Date addtime;// 存放添加时间
public Date getAddtime() { public Date getAddtime() {
return addtime; return addtime;
} }
public void setAddtime(Date addtime) { public void setAddtime(Date addtime) {
this.addtime = addtime; this.addtime = addtime;// 设置添加时间
} }
public Long getId() { public Long getId() {
@ -74,7 +78,7 @@ public class LeixingEntity<T> implements Serializable {
} }
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;// 设置类型ID
} }
/** /**
* *

@ -1,157 +1,144 @@
package com.entity.model; package com.entity.model;
import com.entity.ForumEntity; import com.entity.ForumEntity;
import java.io.Serializable; // 导入可序列化接口
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 * entity
* ModelAndView model * ModelAndViewmodel
*
* @author * @author
* @email * @email
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
public class ForumModel implements Serializable { public class ForumModel implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L; // 版本控制
/** /**
* *
*/ */
private String content; // 存放帖子内容
private String content;
/** /**
* id * id
*/ */
private Long parentid; // 存放父节点ID
private Long parentid;
/** /**
* id * 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) { public void setContent(String content) {
this.content = content; this.content = content; // 设置帖子内容
} }
/** /**
* *
* @return
*/ */
public String getContent() { public String getContent() {
return content; return content;
} }
/** /**
* id * id
* @param parentid ID
*/ */
public void setParentid(Long parentid) { public void setParentid(Long parentid) {
this.parentid = parentid; this.parentid = parentid; // 设置父节点ID
} }
/** /**
* id * id
* @return ID
*/ */
public Long getParentid() { public Long getParentid() {
return parentid; return parentid; // 返回父节点ID
} }
/** /**
* id * id
* @param userid ID
*/ */
public void setUserid(Long userid) { public void setUserid(Long userid) {
this.userid = userid; this.userid = userid; // 设置用户ID
} }
/** /**
* id * id
* @return ID
*/ */
public Long getUserid() { public Long getUserid() {
return userid; return userid;
} }
/** /**
* *
* @param username
*/ */
public void setUsername(String username) { public void setUsername(String username) {
this.username = username; this.username = username; // 设置用户名
} }
/** /**
* *
* @return
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
/** /**
* *
* @param avatarurl URL
*/ */
public void setAvatarurl(String avatarurl) { public void setAvatarurl(String avatarurl) {
this.avatarurl = avatarurl; this.avatarurl = avatarurl; // 设置头像URL
} }
/** /**
* *
* @return URL
*/ */
public String getAvatarurl() { public String getAvatarurl() {
return avatarurl; return avatarurl;
} }
/** /**
* *
* @param isdone
*/ */
public void setIsdone(String isdone) { public void setIsdone(String isdone) {
this.isdone = isdone; this.isdone = isdone; // 设置帖子状态
} }
/** /**
* *
* @return
*/ */
public String getIsdone() { public String getIsdone() {
return isdone; return isdone;
} }
} }

@ -19,7 +19,7 @@ import java.io.Serializable;
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
public class LeixingModel implements Serializable { public class LeixingModel implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;// 版本控制
// 可以根据需求定义属性,例如类型的名称、描述等
} }

@ -24,13 +24,15 @@ public class ForumView extends ForumEntity implements Serializable {
public ForumView(){ public ForumView(){
} }
public ForumView(ForumEntity forumEntity){ // 接收 ForumEntity 对象的构造函数
public ForumView(ForumEntity forumEntity) {
try { try {
// 将ForumEntity的属性复制到当前ForumView对象
BeanUtils.copyProperties(this, forumEntity); BeanUtils.copyProperties(this, forumEntity);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block // 异常处理,打印堆栈信息
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

@ -24,13 +24,14 @@ public class LeixingView extends LeixingEntity implements Serializable {
public LeixingView(){ public LeixingView(){
} }
public LeixingView(LeixingEntity leixingEntity){ // 接收 LeixingEntity 对象的构造函数
public LeixingView(LeixingEntity leixingEntity) {
try { try {
// 将LeixingEntity的属性复制到当前LeixingView对象
BeanUtils.copyProperties(this, leixingEntity); BeanUtils.copyProperties(this, leixingEntity);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block // 异常处理,打印堆栈信息
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

@ -19,7 +19,7 @@ import java.io.Serializable;
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
public class LeixingVO implements Serializable { public class LeixingVO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;// 版本控制,用于序列化
} }

@ -3,8 +3,8 @@ package com.service;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;// 导入MyBatis-Plus的Wrapper接口用于构建查询条件
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;// 导入MyBatis-Plus的服务接口
import com.entity.ConfigEntity; import com.entity.ConfigEntity;
import com.utils.PageUtils; import com.utils.PageUtils;
@ -13,5 +13,12 @@ import com.utils.PageUtils;
* *
*/ */
public interface ConfigService extends IService<ConfigEntity> { public interface ConfigService extends IService<ConfigEntity> {
PageUtils queryPage(Map<String, Object> params,Wrapper<ConfigEntity> wrapper);
/**
*
* @param params
* @param wrapper
* @return
*/
PageUtils queryPage(Map<String, Object> params, Wrapper<ConfigEntity> wrapper);
} }

@ -3,14 +3,12 @@ package com.service;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.utils.PageUtils; import com.utils.PageUtils;
import com.entity.ForumEntity; import com.entity.ForumEntity; // 导入论坛实体类
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.entity.vo.ForumVO; import com.entity.vo.ForumVO;// 导入论坛VO类
import org.apache.ibatis.annotations.Param; 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<ForumEntity> { public interface ForumService extends IService<ForumEntity> {
/**
*
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
/**
* VO
* @param wrapper
* @return ForumVO
*/
List<ForumVO> selectListVO(Wrapper<ForumEntity> wrapper); List<ForumVO> selectListVO(Wrapper<ForumEntity> wrapper);
/**
* VO
* @param wrapper
* @return ForumVO
*/
ForumVO selectVO(@Param("ew") Wrapper<ForumEntity> wrapper); ForumVO selectVO(@Param("ew") Wrapper<ForumEntity> wrapper);
/**
*
* @param wrapper
* @return ForumView
*/
List<ForumView> selectListView(Wrapper<ForumEntity> wrapper); List<ForumView> selectListView(Wrapper<ForumEntity> wrapper);
/**
*
* @param wrapper
* @return ForumView
*/
ForumView selectView(@Param("ew") Wrapper<ForumEntity> wrapper); ForumView selectView(@Param("ew") Wrapper<ForumEntity> wrapper);
PageUtils queryPage(Map<String, Object> params,Wrapper<ForumEntity> wrapper); /**
*
* @param params
* @param wrapper
* @return
*/
PageUtils queryPage(Map<String, Object> params, Wrapper<ForumEntity> wrapper);
} }

@ -3,12 +3,12 @@ package com.service;
import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.IService; import com.baomidou.mybatisplus.service.IService;
import com.utils.PageUtils; import com.utils.PageUtils;
import com.entity.LeixingEntity; import com.entity.LeixingEntity; // 导入类型实体类
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.entity.vo.LeixingVO; import com.entity.vo.LeixingVO;
import org.apache.ibatis.annotations.Param; 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<LeixingEntity> { public interface LeixingService extends IService<LeixingEntity> {
/**
*
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
/**
* VO
* @param wrapper
* @return LeixingVO
*/
List<LeixingVO> selectListVO(Wrapper<LeixingEntity> wrapper); List<LeixingVO> selectListVO(Wrapper<LeixingEntity> wrapper);
/**
* VO
* @param wrapper
* @return LeixingVO
*/
LeixingVO selectVO(@Param("ew") Wrapper<LeixingEntity> wrapper); LeixingVO selectVO(@Param("ew") Wrapper<LeixingEntity> wrapper);
/**
*
* @param wrapper
* @return LeixingView
*/
List<LeixingView> selectListView(Wrapper<LeixingEntity> wrapper); List<LeixingView> selectListView(Wrapper<LeixingEntity> wrapper);
/**
*
* @param wrapper
* @return LeixingView
*/
LeixingView selectView(@Param("ew") Wrapper<LeixingEntity> wrapper); LeixingView selectView(@Param("ew") Wrapper<LeixingEntity> wrapper);
PageUtils queryPage(Map<String, Object> params,Wrapper<LeixingEntity> wrapper); /**
*
* @param params
* @param wrapper
* @return
*/
PageUtils queryPage(Map<String, Object> params, Wrapper<LeixingEntity> wrapper);
} }

@ -20,26 +20,70 @@ import com.entity.view.WenjuandafuView;
*/ */
public interface WenjuandafuService extends IService<WenjuandafuEntity> { public interface WenjuandafuService extends IService<WenjuandafuEntity> {
/**
*
* @param params
* @return
*/
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
/**
* VO
* @param wrapper
* @return VO
*/
List<WenjuandafuVO> selectListVO(Wrapper<WenjuandafuEntity> wrapper); List<WenjuandafuVO> selectListVO(Wrapper<WenjuandafuEntity> wrapper);
/**
* VO
* @param wrapper
* @return VO
*/
WenjuandafuVO selectVO(@Param("ew") Wrapper<WenjuandafuEntity> wrapper); WenjuandafuVO selectVO(@Param("ew") Wrapper<WenjuandafuEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
List<WenjuandafuView> selectListView(Wrapper<WenjuandafuEntity> wrapper); List<WenjuandafuView> selectListView(Wrapper<WenjuandafuEntity> wrapper);
/**
*
* @param wrapper
* @return
*/
WenjuandafuView selectView(@Param("ew") Wrapper<WenjuandafuEntity> wrapper); WenjuandafuView selectView(@Param("ew") Wrapper<WenjuandafuEntity> wrapper);
PageUtils queryPage(Map<String, Object> params,Wrapper<WenjuandafuEntity> wrapper); /**
*
* @param params
List<Map<String, Object>> selectValue(Map<String, Object> params,Wrapper<WenjuandafuEntity> wrapper); * @param wrapper
* @return
List<Map<String, Object>> selectTimeStatValue(Map<String, Object> params,Wrapper<WenjuandafuEntity> wrapper); */
PageUtils queryPage(Map<String, Object> params, Wrapper<WenjuandafuEntity> wrapper);
List<Map<String, Object>> selectGroup(Map<String, Object> params,Wrapper<WenjuandafuEntity> wrapper);
/**
* Map
* @param params
* @param wrapper
* @return Map
*/
List<Map<String, Object>> selectValue(Map<String, Object> params, Wrapper<WenjuandafuEntity> wrapper);
/**
*
* @param params
* @param wrapper
* @return Map
*/
List<Map<String, Object>> selectTimeStatValue(Map<String, Object> params, Wrapper<WenjuandafuEntity> wrapper);
} /**
*
* @param params
* @param wrapper
* @return Map
*/
List<Map<String, Object>> selectGroup(Map<String, Object> params, Wrapper<WenjuandafuEntity> wrapper);

@ -24,10 +24,10 @@ import com.utils.Query;
public class ConfigServiceImpl extends ServiceImpl<ConfigDao, ConfigEntity> implements ConfigService { public class ConfigServiceImpl extends ServiceImpl<ConfigDao, ConfigEntity> implements ConfigService {
@Override @Override
public PageUtils queryPage(Map<String, Object> params, Wrapper<ConfigEntity> wrapper) { public PageUtils queryPage(Map<String, Object> params, Wrapper<ConfigEntity> wrapper) {
// 使用MyBatis-Plus的selectPage方法进行分页查询
Page<ConfigEntity> page = this.selectPage( Page<ConfigEntity> page = this.selectPage(
new Query<ConfigEntity>(params).getPage(), new Query<ConfigEntity>(params).getPage(), // 获取分页参数
wrapper wrapper // 查询条件
); );
return new PageUtils(page); return new PageUtils(page); // 返回分页结果
}
} }

@ -18,46 +18,76 @@ import com.service.ForumService;
import com.entity.vo.ForumVO; import com.entity.vo.ForumVO;
import com.entity.view.ForumView; import com.entity.view.ForumView;
@Service("forumService") @Service("forumService") // 将该类标记为Spring的Service组件
public class ForumServiceImpl extends ServiceImpl<ForumDao, ForumEntity> implements ForumService { public class ForumServiceImpl extends ServiceImpl<ForumDao, ForumEntity> implements ForumService {
/**
*
* @param params
* @return
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
// 调用selectPage方法进行分页查询
Page<ForumEntity> page = this.selectPage( Page<ForumEntity> page = this.selectPage(
new Query<ForumEntity>(params).getPage(), new Query<ForumEntity>(params).getPage(), // 获取分页信息
new EntityWrapper<ForumEntity>() new EntityWrapper<ForumEntity>() // 创建查询条件
); );
return new PageUtils(page); return new PageUtils(page); // 返回分页结果
} }
/**
*
* @param params
* @param wrapper
* @return
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params, Wrapper<ForumEntity> wrapper) { public PageUtils queryPage(Map<String, Object> params, Wrapper<ForumEntity> wrapper) {
Page<ForumView> page =new Query<ForumView>(params).getPage(); // 创建分页对象
page.setRecords(baseMapper.selectListView(page,wrapper)); Page<ForumView> page = new Query<ForumView>(params).getPage();
PageUtils pageUtil = new PageUtils(page); // 设置记录
return pageUtil; page.setRecords(baseMapper.selectListView(page, wrapper));
return new PageUtils(page); // 返回分页结果
} }
/**
* VO
* @param wrapper
* @return VO
*/
@Override @Override
public List<ForumVO> selectListVO(Wrapper<ForumEntity> wrapper) { public List<ForumVO> selectListVO(Wrapper<ForumEntity> wrapper) {
return baseMapper.selectListVO(wrapper); return baseMapper.selectListVO(wrapper); // 调用数据访问对象方法返回VO对象列表
} }
/**
* VO
* @param wrapper
* @return VO
*/
@Override @Override
public ForumVO selectVO(Wrapper<ForumEntity> wrapper) { public ForumVO selectVO(Wrapper<ForumEntity> wrapper) {
return baseMapper.selectVO(wrapper); return baseMapper.selectVO(wrapper); // 调用数据访问对象方法返回单个VO对象
} }
/**
*
* @param wrapper
* @return
*/
@Override @Override
public List<ForumView> selectListView(Wrapper<ForumEntity> wrapper) { public List<ForumView> selectListView(Wrapper<ForumEntity> wrapper) {
return baseMapper.selectListView(wrapper); return baseMapper.selectListView(wrapper); // 调用数据访问对象方法,返回视图对象列表
} }
/**
*
* @param wrapper
* @return
*/
@Override @Override
public ForumView selectView(Wrapper<ForumEntity> wrapper) { public ForumView selectView(Wrapper<ForumEntity> wrapper) {
return baseMapper.selectView(wrapper); return baseMapper.selectView(wrapper); // 调用数据访问对象方法,返回单个视图对象
} }
} }

@ -17,47 +17,75 @@ import com.entity.LeixingEntity;
import com.service.LeixingService; import com.service.LeixingService;
import com.entity.vo.LeixingVO; import com.entity.vo.LeixingVO;
import com.entity.view.LeixingView; import com.entity.view.LeixingView;
@Service("leixingService") // 将该类标记为Spring的Service组件
@Service("leixingService")
public class LeixingServiceImpl extends ServiceImpl<LeixingDao, LeixingEntity> implements LeixingService { public class LeixingServiceImpl extends ServiceImpl<LeixingDao, LeixingEntity> implements LeixingService {
/**
*
* @param params
* @return
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
// 使用selectPage方法进行分页查询
Page<LeixingEntity> page = this.selectPage( Page<LeixingEntity> page = this.selectPage(
new Query<LeixingEntity>(params).getPage(), new Query<LeixingEntity>(params).getPage(), // 获取分页信息
new EntityWrapper<LeixingEntity>() new EntityWrapper<LeixingEntity>() // 创建查询条件
); );
return new PageUtils(page); return new PageUtils(page); // 返回分页结果
} }
/**
*
* @param params
* @param wrapper
* @return
*/
@Override @Override
public PageUtils queryPage(Map<String, Object> params, Wrapper<LeixingEntity> wrapper) { public PageUtils queryPage(Map<String, Object> params, Wrapper<LeixingEntity> wrapper) {
Page<LeixingView> page =new Query<LeixingView>(params).getPage(); // 创建分页对象
page.setRecords(baseMapper.selectListView(page,wrapper)); Page<LeixingView> page = new Query<LeixingView>(params).getPage();
PageUtils pageUtil = new PageUtils(page); // 设置记录
return pageUtil; page.setRecords(baseMapper.selectListView(page, wrapper));
return new PageUtils(page); // 返回分页结果
} }
/**
* VO
* @param wrapper
* @return VO
*/
@Override @Override
public List<LeixingVO> selectListVO(Wrapper<LeixingEntity> wrapper) { public List<LeixingVO> selectListVO(Wrapper<LeixingEntity> wrapper) {
return baseMapper.selectListVO(wrapper); return baseMapper.selectListVO(wrapper); // 调用数据访问对象方法返回VO对象列表
} }
/**
* VO
* @param wrapper
* @return VO
*/
@Override @Override
public LeixingVO selectVO(Wrapper<LeixingEntity> wrapper) { public LeixingVO selectVO(Wrapper<LeixingEntity> wrapper) {
return baseMapper.selectVO(wrapper); return baseMapper.selectVO(wrapper); // 调用数据访问对象方法返回单个VO对象
} }
/**
*
* @param wrapper
* @return
*/
@Override @Override
public List<LeixingView> selectListView(Wrapper<LeixingEntity> wrapper) { public List<LeixingView> selectListView(Wrapper<LeixingEntity> wrapper) {
return baseMapper.selectListView(wrapper); return baseMapper.selectListView(wrapper); // 调用数据访问对象方法,返回视图对象列表
} }
/**
*
* @param wrapper
* @return
*/
@Override @Override
public LeixingView selectView(Wrapper<LeixingEntity> wrapper) { public LeixingView selectView(Wrapper<LeixingEntity> wrapper) {
return baseMapper.selectView(wrapper); return baseMapper.selectView(wrapper); // 调用数据访问对象方法,返回单个视图对象
} }
}

@ -1,7 +1,7 @@
package com.utils; package com.utils;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;// 导入File类
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -11,17 +11,26 @@ import java.io.InputStream;
*/ */
public class FileUtil { public class FileUtil {
/**
*
* @param file
* @return
* @throws IOException
*/
public static byte[] FileToByte(File file) throws IOException { public static byte[] FileToByte(File file) throws IOException {
// 将数据转为流 // 将文件数据转为输入
@SuppressWarnings("resource") @SuppressWarnings("resource") // 这个资源在方法末尾会自动关闭,抑制编译警告
InputStream content = new FileInputStream(file); InputStream content = new FileInputStream(file); // 创建FileInputStream对象读取文件
ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); // 创建字节数组输出流对象
byte[] buff = new byte[100]; byte[] buff = new byte[100];
int rc = 0; int rc = 0;
// 循环读取文件数据,直到文件结束
while ((rc = content.read(buff, 0, 100)) > 0) { while ((rc = content.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc); swapStream.write(buff, 0, rc); // 将读取的数据写入字节数组输出流
} }
// 获得二进制数组
return swapStream.toByteArray(); return swapStream.toByteArray();
} }
} }

Loading…
Cancel
Save