之前是,直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,麻烦. 通过使用@MapperScan可以指定要扫描的Mapper类的包的路径,比如: @SpringBootApplication @MapperScan("com.lz.water.monitor.mapper")//添加对mapper包扫描 public class Application { public static void main(String[] args) {
从mybatis3.4.0开始加入了@Mapper注解,目的就是为了不再写mapper映射文件 现在项目中的配置 public interface DemoMapper{ int deleteByPrimaryKey(Integer id);} @MapperScan("com.mapper")public class DlxRrsApplication {} 原因: 我们定义DemoMapper类,但是并没有在该类上定义类似@Service或者@Mapper之类的注解,那么为什么可以