界面设计网站推荐,有哪些建设工程类网站,个人怎么缴纳社保,微网站开发价格在实际项目中#xff0c;Dao层会包含很多接口#xff0c;这样会导致spring配置文件过于臃肿。这时就需要采用扫描包的形式来配置mybaits中的映射器。 采用MapperScannerConfigurer来实现。 MapperScannerConfigurer类在spring配置文件中可以配置以下几个属性#xff1a; 1.b…在实际项目中Dao层会包含很多接口这样会导致spring配置文件过于臃肿。这时就需要采用扫描包的形式来配置mybaits中的映射器。 采用MapperScannerConfigurer来实现。 MapperScannerConfigurer类在spring配置文件中可以配置以下几个属性 1.basePackage用于指定映射接口文件的包路径当需要扫描多个包时使用逗号或分号隔开。 2.annotationClass:指定了要扫描的注解名称,只有被注解标示的类才会被配置为映射器。 3.markerInterface指定创建映射器的接口。 4.sqlSessionFactoryBeanName指定在spring中定义的sqlSessionFactory的bean名称。 5.sqlSessionTemplateBeanName指定在spring中定义的sqlSessionTemplate的bean名称。如果定义此属性那么sqlSessionFactoryBeanName将不起作用。 例如 CustomerMapper 接口用Repository表示此接口是一个dao层。 Repository//标示是一个dao层public interface CustomerMapper { public Customer findCustomerById(Integer id);}mapper映射文件 mapper namespacecom.itheima.po.mapper.CustomerMapper select idfindCustomerById parameterTypeInteger resultTypecustomer select * from t_customer where id#{id} /select/mapper在spring的配置文件中配置 !--基于MapperScannerConfigurer的开发--bean classorg.mybatis.spring.mapper.MapperScannerConfigurer property namebasePackage valuecom.itheima.po.mapper///用于扫描映射文件包可以将映射文件放入不同的包中。 property namesqlSessionFactoryBeanName valuesqlSessionFactory///value值是配置mybatis工厂时的id值sqlSessionFactory property nameannotationClass valueorg.springframework.stereotype.Repository///根据注解进行扫描成mapper对象。/bean最后测试成功。 转载于:https://www.cnblogs.com/jasonboren/p/10598083.html