From e074130ae0feccf3a3561e0e90e5e1f4e0793278 Mon Sep 17 00:00:00 2001 From: p2x9nfpei <2196435763@qq.com> Date: Mon, 28 Apr 2025 20:52:13 +0800 Subject: [PATCH] Update ForumServiceImpl.java --- ForumServiceImpl.java | 108 ++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 41 deletions(-) diff --git a/ForumServiceImpl.java b/ForumServiceImpl.java index 770fa8e..49f3c95 100644 --- a/ForumServiceImpl.java +++ b/ForumServiceImpl.java @@ -1,41 +1,67 @@ -package com.service.impl; - -import com.utils.StringUtil; -import com.service.DictionaryService; -import com.utils.ClazzDiff; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import java.lang.reflect.Field; -import java.util.*; -import com.baomidou.mybatisplus.plugins.Page; -import com.baomidou.mybatisplus.service.impl.ServiceImpl; -import org.springframework.transaction.annotation.Transactional; -import com.utils.PageUtils; -import com.utils.Query; -import org.springframework.web.context.ContextLoader; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; -import com.dao.ForumDao; -import com.entity.ForumEntity; -import com.service.ForumService; -import com.entity.view.ForumView; - -/** - * 健身论坛 服务实现类 - */ -@Service("forumService") -@Transactional -public class ForumServiceImpl extends ServiceImpl implements ForumService { - - @Override - public PageUtils queryPage(Map params) { - Page page =new Query(params).getPage(); - page.setRecords(baseMapper.selectListView(page,params)); - return new PageUtils(page); - } - - -} +// 定义包名为 com.service.impl +package com.service.impl; + +// 导入 com.utils 包下的 StringUtil 类 +import com.utils.StringUtil; +// 导入 com.service 包下的 DictionaryService 接口 +import com.service.DictionaryService; +// 导入 com.utils 包下的 ClazzDiff 类 +import com.utils.ClazzDiff; +// 导入 Spring 框架的 BeanUtils 类 +import org.springframework.beans.BeanUtils; +// 导入 Spring 框架的 Autowired 注解 +import org.springframework.beans.factory.annotation.Autowired; +// 导入 Spring 框架的 Service 注解 +import org.springframework.stereotype.Service; +// 导入 Java 反射机制中的 Field 类 +import java.lang.reflect.Field; +// 导入 Java 集合框架中的相关类 +import java.util.*; +// 导入 MyBatis-Plus 的 Page 类 +import com.baomidou.mybatisplus.plugins.Page; +// 导入 MyBatis-Plus 的 ServiceImpl 类 +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +// 导入 Spring 框架的 Transactional 注解 +import org.springframework.transaction.annotation.Transactional; +// 导入自定义的 PageUtils 类 +import com.utils.PageUtils; +// 导入自定义的 Query 类 +import com.utils.Query; +// 导入 Spring 框架的 ContextLoader 类 +import org.springframework.web.context.ContextLoader; +// 导入 Servlet 上下文类 +import javax.servlet.ServletContext; +// 导入 HTTP 请求类 +import javax.servlet.http.HttpServletRequest; +// 导入 Spring 框架的 Nullable 注解 +import org.springframework.lang.Nullable; +// 导入 Spring 框架的 Assert 类 +import org.springframework.util.Assert; +// 导入数据访问对象 ForumDao 接口 +import com.dao.ForumDao; +// 导入实体类 ForumEntity +import com.entity.ForumEntity; +// 导入服务接口 ForumService +import com.service.ForumService; +// 导入视图类 ForumView +import com.entity.view.ForumView; + +// 使用 Spring 的 Service 注解,将该类标记为服务组件,名称为 forumService +@Service("forumService") +// 使用 Spring 的 Transactional 注解,开启事务管理 +@Transactional +// 定义 ForumServiceImpl 类,继承自 MyBatis-Plus 的 ServiceImpl 类,并实现 ForumService 接口 +public class ForumServiceImpl extends ServiceImpl implements ForumService { + + // 重写 ForumService 接口中的 queryPage 方法 + @Override + // 定义 queryPage 方法,用于查询分页数据,接收一个包含查询参数的 Map 对象 + public PageUtils queryPage(Map params) { + // 根据传入的参数创建一个 ForumView 类型的分页对象 + Page page =new Query(params).getPage(); + // 调用 baseMapper 的 selectListView 方法查询数据列表,并设置到分页对象中 + page.setRecords(baseMapper.selectListView(page,params)); + // 根据分页对象创建 PageUtils 对象并返回 + return new PageUtils(page); + } +} \ No newline at end of file