The use of MyBatis-Plus general IService

In addition to the general Mapper, MybatisPlus also has a general Servcie layer, which also reduces the corresponding code workload and extracts the general interface to the public. In fact, according to the idea of ​​MybatisPlus, you can also implement some general Controllers yourself.
1. Only general Mapper
The following three classes are the first to use mybatisPlus writing method, so that some general methods can only be called through SysMenuMapper.
SysMenuMapper

package com.komorebi.mapper;

import com.komorebi.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
public interface SysMenuMapper extends BaseMapper<SysMenu>{
    
    

}

SysMenuService

package com.komorebi.service;

import com.komorebi.entity.SysMenu;
import com.baomidou.mybatisplus.extension.service.IService;

public interface SysMenuService {
    
    
}

SysMenuServiceImpl

package com.komorebi.service.impl;

import com.komorebi.entity.SysMenu;
import com.komorebi.mapper.SysMenuMapper;
import com.komorebi.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class SysMenuServiceImpl implements SysMenuService {
    
    
}

2. General Iservice

package com.komorebi.mapper;

import com.komorebi.entity.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
public interface SysMenuMapper extends BaseMapper<SysMenu> {
    
    

}

SysMenuService inherits the generic IService
SysMenuService extends IService

package com.komorebi.service;

import com.komorebi.entity.SysMenu;
import com.baomidou.mybatisplus.extension.service.IService;

public interface SysMenuService extends IService<SysMenu> {
    
    
}

The service layer needs to inherit IService, of course, the implementation layer also needs to inherit the corresponding implementation class ServiceImpl.

package com.komorebi.service.impl;

import com.komorebi.entity.SysMenu;
import com.komorebi.mapper.SysMenuMapper;
import com.komorebi.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
    
    

}

As mentioned above, our SysMenuService and SysMenuServiceImpl can call some common methods.
For example: SysMenuService.list() = "Query all the information of the corresponding SysMenu table.
SysMenuService.getById(List) = "parameter list id, return value SysMenu list.

Guess you like

Origin blog.csdn.net/weixin_43424325/article/details/121503645