org.mybatis.spring.mapper.MapperScannerConfigurer

该组件可以批量注册*Mapper接口的bean

首先,在spring配置文件中定义:

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="annotationClass" value="org.springframework.stereotype.Repository"/>
        <property name="basePackage" value="cn.jesong.webcall.report.dao"/>
        <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
    </bean>


然后在*Mapper接口(比如UserMapper)中加入注解@Repository("userMapper")

@Repository("userMapper")
public interface UserMapper {
    User selectById(Integer id);

    List<User> selectAll();
}

即可在其他bean中使用:

@Resource

UserMapper userMapper;



猜你喜欢

转载自blog.csdn.net/mr_orange_klj/article/details/80321359