如何設定Spring Boot掃描mapper檔案

來源:互聯網
上載者:User

標籤:XML   --   ica   font   figure   public   產生   ati   ota   

一、掃描mapper介面檔案:

1、推薦:

在Application.java開機檔案中,加註解:

@MapperScan("com.xxx.mapper")

2、

@Mapper
因為我的mapper是一個模組,portal一個模組.
mapper在com.xxx.mapper下
portal的groupid是com.xxx,這樣可以@Mapper直接掃描到.
但是
mybatis-generator產生的mapper並沒有@mapper,即使折騰出來了,雖然對運行效率不會有什麼影響,啟動就會變慢,浪費時間,所以不推薦。

 二、掃描mapper.xml檔案

1、application.properties配置:mybatis.mapper-locations: classpath:mappers/*.xml

2、

<!-- 配置掃描包,載入mapper代理對象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx.mapper"></property>
</bean>

 

@SpringBootApplication
@ImportResource(locations = "classpath:spring-dao.xml")
public class PortalApplication {

 

public static void main(String[] args) {
SpringApplication.run(PortalApplication.class, args);
}
}

 

如何設定Spring Boot掃描mapper檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.