SpringBoot 在原mybatis项目上的使用 通用Mapper

目录

①导入依赖

②启动器上所用mapperScan包改为

③ mapper 需要 extends Mapper

③ 通用Mapper的使用


①导入依赖

<!-- 通用Mapper启动器 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>${mapper.starter.version}</version>
        </dependency>

<mapper.starter.version>2.0.2</mapper.starter.version>

②启动器上所用mapperScan包改为

import tk.mybatis.spring.annotation.MapperScan;

例子

package com.leyou;

import tk.mybatis.spring.annotation.MapperScan;  <--用这个-->


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.leyou.item.mapper")
public class LyItemService {

    public static void main(String[] args) {

        SpringApplication.run(LyItemService.class, args);
    }

}

③ mapper 需要 extends Mapper<Entity>

import com.leyou.item.pojo.Spu;
import tk.mybatis.mapper.common.Mapper;


public interface SpuMapper extends Mapper<Spu> {
}

 

③ 通用Mapper的使用

关于通用Mapper的使用在https://blog.csdn.net/weixin_43155696/article/details/100594379中已经讲到

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章