首页 新闻 赞助 找找看

spring整合ibatis问题

0
悬赏园豆:20 [已解决问题] 解决于 2017-11-08 16:24

     spring整合ibatis配置文件:

 

    

 

 

 

 

 

 

 

此处为何要配置SqlMapClient并注入,而且在调用的时候用的是SqlMapClientTemplate。另外,SqlMapClientTemplate是什么时候被实例化的呢?

 

 

该类继承了SqlMapClientDaoSupport

 

 

 

rm_rf的主页 rm_rf | 初学一级 | 园豆:6
提问于:2017-10-29 13:36
< >
分享
最佳答案
0

如果是java 我可以提供 配置相关

收获园豆:20
螽斯羽 | 初学一级 |园豆:97 | 2017-10-29 21:40

???

rm_rf | 园豆:6 (初学一级) | 2017-10-29 21:41

我是想知道为什么这么写

rm_rf | 园豆:6 (初学一级) | 2017-10-29 21:41

@rm_rf: 在源码中  可以 看到需求组的信息 二球你使用的这个类基本上是不怎么用到的 商业开发没什么 价值  一般使用工厂的 那个类 SqlSessionFactoryBeann

螽斯羽 | 园豆:97 (初学一级) | 2017-10-29 21:46

@rm_rf: myBatis 一大推的 配置 加上套用配置 写起来比较麻烦

 

主配置

 

本来要上传图片的结果是没开通博客无法上传 配置中有域名 不好意思 我上传局部

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
    <context:property-placeholder location="classpath:db.properties"
        system-properties-mode="NEVER" />
    <!-- 配置mybatis主题文件的位置 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <!-- 配置映射文件的位置 -->
        <property name="mapperLocations"
            value="classpath:要扫描的mapper路径*Mapper.xml" />
        <!-- 配置连接池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 配置需要生成别名的包 -->
        <property name="typeAliasesPackage" value="一个项目结构的域名" />
    </bean>
    <!-- p配置事务管理器 -->
    <bean id="txManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />

        <!-- 配置事物环绕 -->
    </bean>
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="list*" read-only="true" />
            <tx:method name="get*" read-only="true" />
            <tx:method name="query*" read-only="true" />
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <!-- 将事务管理的业务织入到指定的位置 -->
    <aop:config>
        <aop:pointcut expression="execution(* 一个项目结构的域名.*.*(..))"
            id="pc" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pc" />
    </aop:config>
    <!--配置连接池对象 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        init-method="init" destroy-method="close">
        <property name="driverClassName" value="${driverClassName}" />
        <property name="url" value="${driverClassName}" />
        <property name="username" value="${username}" />
        <property name="password" value="${password}" />
    </bean>
    <!-- 设置包含 -->
    <import resource="classpath:applicationContext-service.xml" />
    <import resource="classpath:applicationContext-action.xml" />
    <import resource="classpath:applicationContext-mapper.xml" />
</beans>

ibatis配合

 

<configuration>
    <settings>
        <!-- 开启延时加载 在需要的时候再去查询相关的数据 -->
        <setting name="lazyLoadingEnabled" value="true" />
        <!-- 设置false 表示按需加载 默认情况下 访问多方的任何属性都会触发延时加载 -->
        <setting name="aggressiveLazyLoading" value="false" />
        <!-- 设置默认会触犯延时加载的方法 默认是是equals clone hashCode toString -->
        <setting name="lazyLoadTriggerMethods" value="clone" />
    </settings>
</configuration>

 

这是三层架构思想

 

螽斯羽 | 园豆:97 (初学一级) | 2017-10-29 22:06

@purple-leaf: 这是个遗留项目,技术都比较过时

rm_rf | 园豆:6 (初学一级) | 2017-10-29 22:35

@purple-leaf: 不好意思,最急没怎么看博客园

谢谢啦

rm_rf | 园豆:6 (初学一级) | 2017-11-08 16:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册