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中已經講到

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