4、springboot+mybatis通用mapper配置

對於dao層裏面的文件,如果想要加載的話,每一個文件都需要註解@Mapper,這樣文件多了,挺麻煩,可以使用通用mapper,這些文件都繼承該文件即可

1、創建統一的mapper

application.yml配置文件下

mapper:

  mappers: com.test.comm.mapper.SqlMapper

該文件要跟其他dao層文件不妨到一個包中

2、添加SqlMapper文件,裏面什麼內容都沒有

public interface SqlMapper {

}

3、使用

public interface ListMapper extends SqlMapper{

}

4、啓動springboot配置@MapperScan,掃描所有dao層

@SpringBootApplication

@MapperScan("com.test.dao")

public class AdminApplication extends SpringBootServletInitializer {

@Override

protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {

return builder.sources(AdminApplication.class);

}

}

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