對於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);
}
}