spring跟mybatis结合后,如果在service层想要调用mybatis的mapper接口方式如下:
1.写一个接口
@Retention(RetentionPolicy.RUNTIME)
public @interface SqlMapper {
}
2. 在spring的配置文件中扫描该接口
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.test.dao" />
<property name="annotationClass" value="com.test.dao.SqlMapper"/>
</bean>
3.在我们根据表生成的mapper接口上加上
@SqlMapper
public interface TestMapper {
.....
}
这样在service层就可以直接用注解调用mybatis的接口了
@Autowired
private TestMapper testMapper;