|
|
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:用于复杂页面展示(可能包含关联数据)
|
|
|
//设计意义:隔离实体与接口数据,避免敏感字段泄露
|
|
|
|
|
|
}
|