MybatisPlus in addition to generalMapper, and there is also a common Servcie layer, which also reduces the corresponding code workload and extracts common interfaces to the public. In fact, according to the idea of MybatisPlus, you can also implement some general controllers by yourself.
1. Only common mappers
The following three classes are the first to use mybatisPlus writing method, so that some common 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>{
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
SysMenuService
package com.komorebi.service;
import com.komorebi.entity.SysMenu;
import com.baomidou.mybatisplus.extension.service.IService;
public interface SysMenuService {
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
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 {
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
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> {
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
SysMenuService inherits general 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> {
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
The service layer needs to inherit IService, and of course the implementation layer must also 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 {
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
After talking about the above definition, our SysMenuService and SysMenuServiceImpl can call some general methods.
For example: () =》 query all information corresponding to the SysMenu table.
(List) =》Argument list id, return value SysMenu list.