Spring boot整合MyBatis-Plus
一、首先在pom.xml的依赖文件中假如MyBatis-Plus的依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
二、mapper接口继承MyBatis-Plus的接口
@Mapper
public interface OrgTypeTreeMapper extends BaseMapper<OrgTypeTree>{
}
BaseMapper为MyBatis-Plus自带的mapper层接口,OrgTypeTree为对应的实体类,实体类对应相应的数据库表
继承以后可以访问对应的接口方法,具体的方法使用可查看MyBatis-Plus的官网:https://mp.baomidou.com/guide/
三、mapper继承接口后可访问mapper层对应的接口方法,同样的service层同样也可以继承,继承以后我们就能直接在控制层访问service这些方法了,不需要我们去写简单的增删改查Sql了
接口及实现类
public interface IOrgTypeTreeService extends IService<OrgTypeTree>{}
public class OrgTypeTreeServiceImpl extends ServiceImpl<OrgTypeTreeMapper,OrgTypeTree> implements IOrgTypeTreeService {}
以上步骤都写好以后我们就能在控制器内实例化service层的对象调用service层的方法了,官网内同样有对方法的介绍,官网的service层接口实际也是调用的mapper的接口
整合就说到这里了,有什么不明白的可以留言联系我呢