@Mapper
1,作用
用在接口上,在编译之后会生成相应的接口实现类
2,位置:
在对应的某个接口类的上面,生成相对应的实现类
@Mapper
public interface ItripUserMapper {
public ItripUser getItripUserById(@Param(value = "id") Long id)throws Exception;
public List<ItripUser> getItripUserListByMap(Map<String,Object> param)throws Exception;
}
@MapperScan
1,作用:
扫描指定包下所有的接口类,然后所有接口在编译之后都会生成相应的实现类
2,位置:
在SpringBootApplication启动类上面使用,如下,说明扫描“cn.cvs.mapper”此包下的所有mapper接口,生成对应的实现类
@MapperScan("cn.cvs.mapper")
@SpringBootApplication
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
二者的区别:
1,@Mapper是队单个接口类的注解,单个操作。(接口少的时候适合使用)
2,@MapperScan是对整个包之下的所有的接口类的注解,是批量的操作。使用@MapperScan之后,接口类就不需要再使用@Mapper注解了
3,@MapperScan可以扫描多个包,参数传一个字符串数组即可。