与不同框架整合时mybatis的使用区别
与不同框架整合时mybatis的使用区别1,mapper,2,普通
//集成通用mapper的mybatis使用
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.esteel.*.bean"/>
<!-- typeAliasesPackage 为这个包下面的所有类生成别名,在配置文件中就可以直接用类名进行引用,而不用写全路径 -->
<!-- <property name="typeAliasesPackage" value="com.esteel.system.bean,com.esteel.search" />
<property name="mapperLocations" value="classpath:config_mybatis/*.xml" /> -->
<property name="configLocation" value="classpath:config_spring/mybatis-config.xml" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" >
<array>
<value> classpath:config_mybatis/**/*.xml</value>
</array>
</property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=oracle
reasonable=true
</value>
</property>
</bean>
<!-- <bean class="com.github.abel533.mapperhelper.MapperInterceptor">
<property name="properties">
<value>
mappers=com.github.abel533.mapper.Mapper
ORDER=BEFORE
</value>
</property>
</bean> -->
</array>
</property>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">//通用mapper直接根据sqlSession这个名字自动装配sqlSession,直接通过mapper用
<constructor-arg index="0" ref="sqlSessionFactory" />
<!-- 如果想要进行批量操作可加入这个属性 -->
<!-- <constructor-arg index="1" value="BATCH" /> -->
</bean>
@Override
@Cacheable(value="getMenuItems",key="'menufolderid='+#item.menufolderid")
public List<OpmMenuitem> getMenuItems(OpmMenuitem item) {
// TODO Auto-generated method stub
return opmMenuitemMapper.select(item);
}
//普通的mybatis使用,如jpa,获取这个sqlSessionTemplate实例用
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource">
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=oracle
reasonable=true
offsetAsPageNum=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean id="sqlSessionTemplate" class="com.esteel.web.utils.ESteelSqlSessionTemplate" c:sqlSessionFactory-ref="sqlSessionFactory"></bean>
@Autowired
public ESteelSqlSessionTemplate sqlSessionTemplate;
@Override
public List<BasSpsxValueBeanVo> spsxPartKeycdpzzzMap() {
return sqlSessionTemplate.selectList("basSpsxValue.spsxPartKeycdpzzzMap");
}