• 博客园Logo
  • 会员
  • 周边
  • 捐助
  • 新闻
  • 博问
  • 闪存
  • 赞助商
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 简洁模式 ... 退出登录
    注册 登录
Y-wee
博客园    首页    新随笔    联系   管理     

Mybatis-Plus Service CRUD 接口

Mybatis-Plus Service CRUD 接口

Mybatis-Plus 提供了一个通用 Service CRUD 接口:IService ,该接口采用 get 查询单行 remove 删除 list 查询集合 page 分页 前缀命名方式区分通用 Mapper 接口:BaseMapper,避免混淆

IService<T> 泛型 T 为任意实体对象

IService<T>拥有默认的实现类:ServiceImpl<M extends BaseMapper<T>, T>

建议如果存在自定义通用 Service 方法的可能,请创建自己的 service接口继承 IService,并创建自己的实现类继承 ServiceImpl,eg:

service接口

package com.yl.mybatis.plus.guigu.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.yl.mybatis.plus.guigu.entity.User;

/**
 * 用户
 *
 * @author Y-wee
 */
public interface UserService extends IService<User> {

}

service接口实现类

package com.yl.mybatis.plus.guigu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yl.mybatis.plus.guigu.entity.User;
import com.yl.mybatis.plus.guigu.mapper.UserMapper;
import com.yl.mybatis.plus.guigu.service.UserService;
import org.springframework.stereotype.Service;

/**
 * 用户
 *
 * @author Y-wee
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

}

这样既可以使用 Mybatis-Plus 提供的默认实现,又可以自定义业务层方法

记得快乐
posted @ 2022-05-12 22:06  Y-wee  阅读(362)  评论(0)  编辑  收藏  举报
会员力量,点亮园子希望
刷新页面返回顶部
Copyright © 2024 Y-wee
Powered by .NET 8.0 on Kubernetes