You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.service.impl;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.utils.PageUtils;
import com.utils.Query;
import com.dao.YonghuDao;
import com.entity.YonghuEntity;
import com.service.YonghuService;
import com.entity.vo.YonghuVO;
import com.entity.view.YonghuView;
@Service("yonghuService")
public class YonghuServiceImpl extends ServiceImpl<YonghuDao, YonghuEntity> implements YonghuService {
//继承ServiceImpl获得MyBatis-Plus内置的基础CRUD方法如insert(), selectById()等)
//实现自定义的YonghuService接口扩展特定业务方法
@Override
public PageUtils queryPage(Map<String, Object> params) {
Page<YonghuEntity> page = this.selectPage(
new Query<YonghuEntity>(params).getPage(),
new EntityWrapper<YonghuEntity>()
);
return new PageUtils(page);
}
//作用:提供用户数据的分页列表(如管理后台的用户表格)
//调用链Controller → 此方法 → MP分页查询 → 返回PageUtils(含数据+分页信息)
@Override
public PageUtils queryPage(Map<String, Object> params, Wrapper<YonghuEntity> wrapper) {
Page<YonghuView> page =new Query<YonghuView>(params).getPage();
page.setRecords(baseMapper.selectListView(page,wrapper));
PageUtils pageUtil = new PageUtils(page);
return pageUtil;
}
//关键点使用YonghuView视图对象而非实体类
//优势:可关联多表数据(如用户+角色信息避免N+1查询问题
@Override
public List<YonghuVO> selectListVO(Wrapper<YonghuEntity> wrapper) {
return baseMapper.selectListVO(wrapper);
}
@Override
public YonghuVO selectVO(Wrapper<YonghuEntity> wrapper) {
return baseMapper.selectVO(wrapper);
}
@Override
public List<YonghuView> selectListView(Wrapper<YonghuEntity> wrapper) {
return baseMapper.selectListView(wrapper);
}
@Override
public YonghuView selectView(Wrapper<YonghuEntity> wrapper) {
return baseMapper.selectView(wrapper);
}
//分层数据转换:
//VO (Value Object):用于接口返回的数据封装
//View用于复杂页面展示可能包含关联数据
//设计意义:隔离实体与接口数据,避免敏感字段泄露
}