您的位置:澳门402永利com > 关于计算机 > 框架搭建,mybatis集成配置

框架搭建,mybatis集成配置

发布时间:2019-11-01 19:09编辑:关于计算机浏览(137)

    计算下哪些用那多个常用框架搭建一个Java Web工程,方便现在更连忙的开支工程。首先得用maven搭建二个多模块的web工程,这里不再赘言,请参见早先的总计:用Maven命令行创立多模块Web项目

    springmvc+mybatis集成配置,springmvc+mybatis

    轻易易行之美,springmvc,mybatis正是贰个很好的大致集成方案,能够满意日常的项目需求。闲暇时光把品种布局文件分享出来,供大家参看:

     

    1.率先大家来看下依赖的pom:

    图片 1 1 <!-- spring --> 2 <dependency> 3 <groupId>org.springframework</groupId> 4 <artifactId>spring-core</artifactId> 5 <version>${spring.version}</version> 6 </dependency> 7 8 <dependency> 9 <groupId>org.springframework</groupId> 10 <artifactId>spring-beans</artifactId> 11 <version>${spring.version}</version> 12 </dependency> 13 14 <dependency> 15 <groupId>org.springframework</groupId> 16 <artifactId>spring-context</artifactId> 17 <version>${spring.version}</version> 18 </dependency> 19 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-tx</artifactId> 23 <version>${spring.version}</version> 24 </dependency> 25 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-web</artifactId> 29 <version>${spring.version}</version> 30 </dependency> 31 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-webmvc</artifactId> 35 <version>${spring.version}</version> 36 </dependency> 37 38 <dependency> 39 <groupId>org.springframework</groupId> 40 <artifactId>spring-jdbc</artifactId> 41 <version>${spring.version}</version> 42 </dependency> 43 44 <dependency> 45 <groupId>org.springframework</groupId> 46 <artifactId>spring-test</artifactId> 47 <version>${spring.version}</version> 48 <scope>test</scope> 49 </dependency> 50 51 <!-- mybatis 包 --> 52 <dependency> 53 <groupId>org.mybatis</groupId> 54 <artifactId>mybatis</artifactId> 55 <version>3.2.8</version> 56 </dependency> 57 58 <!--mybatis spring 插件 --> 59 <dependency> 60 <groupId>org.mybatis</groupId> 61 <artifactId>mybatis-spring</artifactId> 62 <version>1.2.2</version> 63 </dependency> 64 65 <!-- mysql连接 --> 66 <dependency> 67 <groupId>mysql</groupId> 68 <artifactId>mysql-connector-java</artifactId> 69 <version>5.1.34</version> 70 </dependency> 71 72 <!-- 数据源 --> 73 <dependency> 74 <groupId>com.alibaba</groupId> 75 <artifactId>druid</artifactId> 76 <version>1.0.12</version> 77 </dependency> 78 79 <dependency> 80 <groupId>org.aspectj</groupId> 81 <artifactId>aspectjweaver</artifactId> 82 <version>1.8.4</version> 83 </dependency> 84 85 <!-- log4j --> 86 <dependency> 87 <groupId>log4j</groupId> 88 <artifactId>log4j</artifactId> 89 <version>1.2.17</version> 90 </dependency> 91 92 <!-- servlet --> 93 <dependency> 94 <groupId>javax.servlet</groupId> 95 <artifactId>servlet-api</artifactId> 96 <version>3.0-alpha-1</version> 97 </dependency> 98 99 <dependency> 100 <groupId>javax.servlet</groupId> 101 <artifactId>jstl</artifactId> 102 <version>1.2</version> 103 </dependency> 104 105 <!-- json --> 106 <dependency> 107 <groupId>org.codehaus.jackson</groupId> 108 <artifactId>jackson-mapper-asl</artifactId> 109 <version>1.9.13</version> 110 </dependency> 111 112 <dependency> 113 <groupId>com.alibaba</groupId> 114 <artifactId>fastjson</artifactId> 115 <version>1.2.3</version> 116 </dependency> 117 118 <dependency> 119 <groupId>com.fasterxml.jackson.core</groupId> 120 <artifactId>jackson-annotations</artifactId> 121 <version>${jackson.version}</version> 122 </dependency> 123 124 <dependency> 125 <groupId>com.fasterxml.jackson.core</groupId> 126 <artifactId>jackson-core</artifactId> 127 <version>${jackson.version}</version> 128 </dependency> 129 130 <dependency> 131 <groupId>com.fasterxml.jackson.core</groupId> 132 <artifactId>jackson-databind</artifactId> 133 <version>${jackson.version}</version> 134 </dependency> 135 <!-- 文件上传 --> 136 <dependency> 137 <groupId>commons-io</groupId> 138 <artifactId>commons-io</artifactId> 139 <version>2.4</version> 140 </dependency> 141 142 <dependency> 143 <groupId>commons-fileupload</groupId> 144 <artifactId>commons-fileupload</artifactId> 145 <version>1.2.2</version> 146 </dependency> View Code

    spring 接收的是4.1.4的本子,遵照系统需求大家能够选用自个儿符合的本子。

    2.唇亡齿寒的布局文件:

        a)spring.xml

    图片 2 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:xsi="" xmlns:context="" 4 xsi:schemaLocation=" 5 6 7 ; 8 9 <!--引进配置属性文件 --> 10 <context:property-placeholder location="classpath:config.properties" /> 11 12 <!--自动扫描含有@Service将其注入为bean --> 13 <context:component-scan base-package="com.demo.report.web.service" /> View Code

        b)spring-mvc.xml

    图片 3 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:mvc="" xmlns:xsi="" 4 xmlns:p="" xmlns:context="" 5 xsi:schemaLocation=" 6 7 8 9 10 ; 11 12 <!-- 自动扫描controller包下的全体类,借使@Controller注入为bean --> 13 <context:component-scan base-package="com.demo.report.web.controller" /> 14 15 <!-- 制止IE执行AJAX时,重回JSON出现下载文件 --> 16 <bean id="mapping杰克逊HttpMessageConverter" 17 class="org.springframework.http.converter.json.Mapping杰克逊2HttpMessageConverter"> 18 <property name="supportedMediaTypes"> 19 <list> 20 <value>text/html;charset=UTF-8</value> 21 </list> 22 </property> 23 </bean> 24 25 <!-- 运行Spring MVC的注释功用,完结央求和注释POJO的炫彩 --> 26 <bean 27 class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 28 <property name="messageConverters"> 29 <list> 30 <!-- json转换器 --> 31 <ref bean="mappingJacksonHttpMessageConverter" /> 32 </list> 33 </property> 34 </bean> 35 36 <!-- 对模型视图名称的深入分析,即在模型视图名称增添前后缀 --> 37 <bean 38 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 39 <property name="viewClass" 40 value="org.springframework.web.servlet.view.JstlView" /> 41 <property name="prefix" value="" /> 42 <property name="suffix" value="" /> 43 </bean> 44 45 <!-- 配置多文件上传 46 <bean id="multipartResolver" 47 class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 48 <property name="defaultEncoding"> 49 <value>UTF-8</value> 50 </property> 51 <property name="maxUploadSize"> 52 <value>32505856</value> 53 </property> 54 <property name="maxInMemorySize"> 55 <value>4096</value> 56 </property> 57 </bean>--> 58 59 </beans> View Code

        c)spring-mybatis.xml

    图片 4 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:xsi="" xmlns:tx="" 4 xmlns:aop="" 5 xsi:schemaLocation=" 6 7 8 9 10 11 12 "> 13 14 <!-- 配置数据源 使用的是Druid数据源 --> 15 <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" 16 init-method="init" destroy-method="close"> 17 <property name="url" value="${jdbc.url}" /> 18 <property name="username" value="${jdbc.username}" /> 19 <property name="password" value="${jdbc.password}" /> 20 21 <!-- 初阶化连接大小 --> 22 <property name="initialSize" value="0" /> 23 <!-- 连接池最大利用连接数量 --> 24 <property name="maxActive" value="20" /> 25 26 <!-- 连接池最小空闲 --> 27 <property name="minIdle" value="0" /> 28 <!-- 获取连接最大等待时间 --> 29 <property name="maxWait" value="60000" /> 30 <property name="poolPreparedStatements" value="true" /> 31 <property name="maxPoolPreparedStatementPerConnectionSize" 32 value="33" /> 33 <!-- 用来检查测试有效sql --> 34 <property name="validationQuery" value="${validationQuery}" /> 35 <property name="testOnBorrow" value="false" /> 36 <property name="testOnReturn" value="false" /> 37 <property name="testWhileIdle" value="true" /> 38 <!-- 配置间隔多长期才开展二回检查评定,检查评定供给关闭的闲暇连接,单位是阿秒 --> 39 <property name="timeBetweenEvictionRunsMillis" value="60000" /> 40 <!-- 配置三个连连在池中微小生存的年月,单位是皮秒 --> 41 <property name="minEvictableIdleTimeMillis" value="25200400" /> 42 <!-- 打开removeAbandoned功能 --> 43 <property name="removeAbandoned" value="true" /> 44 <!-- 1800秒,也就是30分钟 --> 45 <property name="removeAbandonedTimeout" value="1800" /> 46 <!-- 关闭abanded连接时输出错误日志 --> 47 <property name="logAbandoned" value="true" /> 48 <!-- 监察和控制数据库 --> 49 <property name="filters" value="mergeStat" /> 50 </bean> 51 52 <!-- myBatis文件 --> 53 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 54 <property name="dataSource" ref="dataSource" /> 55 <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 --> 56 <property name="mapperLocations" value="classpath:com/demo/report/web/mapper/*.xml" /> 57 </bean> 58 59 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 60 <property name="basePackage" value="com.feidai.report.web.mapper" /> 61 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> 62 </bean> 63 64 <!-- 配置事务管理器 --> 65 <bean id="transactionManager" 66 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 67 <property name="dataSource" ref="dataSource" /> 68 </bean> View Code

        d)web.xml

    图片 5 1 <display-name>springmvc_mybatis_demo</display-name> 2 3 <context-param> 4 <param-name>contextConfigLocation</param-name> 5 <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value> 6 </context-param> 7 8 <filter> 9 <filter-name>encodingFilter</filter-name> 10 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 11 <init-param> 12 <param-name>encoding</param-name> 13 <param-value>utf-8</param-value> 14 </init-param> 15 <init-param> 16 <param-name>forceEncoding</param-name> 17 <param-value>true</param-value> 18 </init-param> 19 </filter> 20 <filter-mapping> 21 <filter-name>encodingFilter</filter-name> 22 <url-pattern>/*</url-pattern> 23 </filter-mapping> 24 25 <listener> 26 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 27 </listener> 28 29 <!-- 防止spring内部存款和储蓄器溢出监听器 --> 30 <listener> 31 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 32 </listener> 33 34 <servlet> 35 <description>spring mvc servlet</description> 36 <servlet-name>rest</servlet-name> 37 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 38 <init-param> 39 <param-name>contextConfigLocation</param-name> 40 <param-value> 41 classpath:spring-mvc.xml 42 </param-value> 43 </init-param> 44 <load-on-startup>1</load-on-startup> 45 </servlet> 46 <servlet-mapping> 47 <servlet-name>rest</servlet-name> 48 <url-pattern>/</url-pattern> 49 </servlet-mapping> 50 51 <servlet> 52 <servlet-name>DruidStatView</servlet-name> 53 <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> 54 </servlet> 55 <servlet-mapping> 56 <servlet-name>DruidStatView</servlet-name> 57 <url-pattern>/druid/*</url-pattern> 58 </servlet-mapping> 59 60 <!-- 配置session超时时间,单位分钟--> 61 <session-config> 62 <session-timeout>30</session-timeout> 63 </session-config> 64 65 <welcome-file-list> 66 <welcome-file>index.jsp</welcome-file> 67 </welcome-file-list> View Code

    选拔了druid的数据源,在web中的详细陈设能够参见代码。

     

    简单之美,springmvc,mybatis正是叁个很好的简要集成方案,能够知足平日的等级次序必要。闲暇时间把项...

    率起头入那些框架所需的maven信任:

    <spring.version>3.2.2.RELEASE</spring.version>
    <v.velocity>1.6.3</v.velocity>
    <v.velocity.tool>1.2</v.velocity.tool>
    <jdbc.driver.version>5.1.15</jdbc.driver.version>

    <!-- ibatis begin -->
    <dependency>
        <groupId>org.apache.ibatis</groupId>
        <artifactId>ibatis-sqlmap</artifactId>
        <version>2.3.4.726</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${jdbc.driver.version}</version>
    </dependency>
    <!-- ibatis end -->

    <!-- spring begin -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <artifactId>spring-context</artifactId>
        <groupId>org.springframework</groupId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- spring end -->

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- velocity begin -->
    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>${v.velocity}</version>
    </dependency>
    <dependency>
        <groupId>velocity-tools</groupId>
        <artifactId>velocity-tools</artifactId>
        <version>${v.velocity.tool}</version>
    </dependency>
    <!-- velocity end -->

        web.xml里配置spring和spring mvc 入口

     <servlet>
      <servlet-name>appServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:spring-config.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
      <servlet-name>appServlet</servlet-name>
      <url-pattern>/</url-pattern>
     </servlet-mapping>
        DispatcherServlet是spring mvc的所有恳求入口的servlet。contextConfigLocation参数配置spring的总局署文件位置。纵然是spring集成struts的话,还索要独自布署spring的监听器,可是只借使集成spring mvc,则无需上边这段配置了:

    <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath:spring-context.xml</param-value>
    </context-param>

        spring总局署文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
          xmlns:xsi=""
          xmlns:context=""
          xmlns:aop=""
          xmlns:mvc=""
          xsi:schemaLocation="
       
       
       
       
       
       
          default-autowire="byName">

        <context:component-scan base-package="com.jd.im.**"/>

        <mvc:annotation-driven/>

        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:im-king.properties</value>
                    <value>classpath:important.properties</value>
                    <value>classpath:jss_config.properties</value>
                </list>
            </property>
        </bean>

        <import resource="spring/spring-config-mvc.xml"></import>
        <import resource="spring/spring-config-datasource.xml"/>
    </beans>
        总布置文件里集成了spring mvc配置文件和ibatis数据源的布局文件。

        spring mvc 配置

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="" xmlns:xsi="" xmlns:context=""
     xmlns:mvc=""
     xsi:schemaLocation="
         
         
         
         
             ;

     <context:component-scan base-package="com.**.dd.mall.web.controller" />
     <mvc:annotation-driven />
     
     <bean id="dateObjectMapper" class="com.**.dd.mall.web.util.DateObjectMapper"></bean>
     <!-- Json重返 乱码管理 -->
     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
      <property name="messageConverters">
       <list>
        <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
         <property name="objectMapper" ref="dateObjectMapper"></property>
        </bean>
        <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
         <property name="supportedMediaTypes">
          <list>
           <value>text/plain;charset=UTF-8</value>
          </list>
         </property>
        </bean>
        <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
        <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
        <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
        <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
       </list>
      </property>
     </bean>

     <mvc:resources mapping="/dist/**" location="/dist/" cache-period="3600" />
     <mvc:resources mapping="/js/**" location="/js/" cache-period="3600" />
     <mvc:resources mapping="/css/**" location="/css/" cache-period="3600" />
     <!--<mvc:resources mapping="/fonts/**" location="/fonts/" cache-period="3600" /> -->
     <mvc:resources mapping="/config.json" location="/" cache-period="3600" />
     <mvc:resources mapping="/image/**" location="/image/" cache-period="3600" />

     <!-- 对转会页面包车型大巴门径深入解析。prefix:前缀, suffix:后缀 -->
     <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
      <property name="cache" value="true"></property>
      <property name="suffix" value=".vm"></property>
      <property name="prefix" value=""></property>
      <property name="contentType" value="text/html;charset=utf-8"></property>
      <property name="exposeRequestAttributes" value="true"></property>
      <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"></property>
     </bean>

     <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
      <property name="resourceLoaderPath" value="/WEB-INF/vm/"></property>
      <property name="configLocation" value="classpath:velocity.properties"></property>
     </bean>

     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
      <property name="maxUploadSize" value="10485760" />
      <property name="defaultEncoding" value="utf-8"></property>
     </bean>

     <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
      <!-- 设置为true以忽视对Accept Header的扶持 -->
      <property name="order" value="1" />
      <property name="contentNegotiationManager">
       <bean class="org.springframework.web.accept.ContentNegotiationManager">
        <constructor-arg>
         <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
          <constructor-arg>
           <map>
            <entry key="json" value="application/json" />
            <entry key="xml" value="application/xml" />
           </map>
          </constructor-arg>
         </bean>
        </constructor-arg>
       </bean>
      </property>
      <property name="ignoreAcceptHeader" value="true" />
      <!-- 在向来不扩张名时即: "/user/getUser" 时的私下认可表现方式 -->
      <property name="defaultContentType" value="text/html" />

      <!-- 用于开启 /user/getUser?format=json 的支撑 -->
      <property name="favorParameter" value="true" />
      <property name="defaultViews">
       <list>
        <!-- for application/json -->
        <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
        </bean>
       </list>
      </property>
     </bean>
     
    </beans>
        viewResolver和velocityConfig节点钦定了spring mv重临页面用velocity。

        Ibatis配置
        带读写分离的数据源配置
    <?xml version="1.0" encoding="GBK"?>
    <beans xmlns=""
          xmlns:xsi="" xmlns:tx=""
          xsi:schemaLocation="
         
           
      "
          default-autowire="byName">

        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${chat.jdbc.driver}"/>
            <property name="url" value="${chat.jdbc.url}"/>
            <property name="username" value="${chat.jdbc.username}"/>
            <property name="password" value="${chat.jdbc.password}"/>
            <property name="maxActive" value="${chat.jdbc.maxActive}"/>
            <!-- sql 心跳 -->
            <property name="testWhileIdle" value="true"/>
            <property name="testOnBorrow" value="false"/>
            <property name="testOnReturn" value="false"/>
            <property name="validationQuery" value="select 1"/>
            <property name="validationQueryTimeout" value="1"/>
            <property name="timeBetweenEvictionRunsMillis" value="60000"/>
            <property name="numTestsPerEvictionRun" value="${chat.jdbc.maxActive}"/>
        </bean>

        <bean id="selectedDataSource" name="selectedDataSource"
              class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${select.chat.jdbc.driver}"/>
            <property name="url" value="${select.chat.jdbc.url}"/>
            <property name="username" value="${select.chat.jdbc.username}"/>
            <property name="password" value="${select.chat.jdbc.password}"/>
            <property name="maxActive" value="${select.chat.jdbc.maxActive}"/>
            <!-- sql 心跳 -->
            <property name="testWhileIdle" value="true"/>
            <property name="testOnBorrow" value="false"/>
            <property name="testOnReturn" value="false"/>
            <property name="validationQuery" value="select 1"/>
            <property name="validationQueryTimeout" value="1"/>
            <property name="timeBetweenEvictionRunsMillis" value="60000"/>
            <property name="numTestsPerEvictionRun" value="${select.chat.jdbc.maxActive}"/>
        </bean>

        <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="configLocations">
                <list>
                    <value>classpath:sqlmap-config.xml</value>
                </list>
            </property>
            <property name="dataSource" ref="dataSource"/>
        </bean>

        <bean id="sqlMapClientRead" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="configLocations">
                <list>
                    <value>classpath:sqlmap-config.xml</value>
                </list>
            </property>
            <property name="dataSource" ref="selectedDataSource"/>
        </bean>

        <bean id="selectDao" class="com.jd.im.king.template.dao.impl.SelectDaoImpl">
            <property name="sqlMapClient" ref="sqlMapClientRead"/>
        </bean>

        <bean id="writeDao" class="com.jd.im.king.template.dao.impl.WriteDaoImpl">
            <property name="sqlMapClient" ref="sqlMapClient"/>
        </bean>

        <bean id="transactionManager"
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>

        <tx:annotation-driven transaction-manager="transactionManager"/>

    </beans>

        Ibatis的询问正视SqlMapClientFactoryBean这些目标的配置。那几个指标同有的时候候钦点了ibatis的总布局文件和数据源。一共配了多个,二个负责读,三个承担写。

        Ibatis总局署文件

    <?xml version="1.0" encoding="GBK"?>
    <!DOCTYPE sqlMapConfig  PUBLIC "-//iBATIS.com//DTD SQL Map
    Config 2.0/" ";

    <sqlMapConfig>
        <settings
                cacheModelsEnabled="true"
                enhancementEnabled="true"
                lazyLoadingEnabled="false"
                errorTracingEnabled="true"
                maxRequests="32"
                maxSessions="10"
                maxTransactions="5"
                useStatementNamespaces="true"/>

        <sqlMap resource="sqlmap/word.xml"/>
       
    </sqlMapConfig>

        sqlMap节点担当导入分配置文件,也正是sql文件。能够有三个。

        ibatis的sql分配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" ";
    <sqlMap namespace="word">
     
     <typeAlias alias="Word" type="com.**.im.RiskKeyWord"/>
     
        <insert id="add" parameterClass="Word">
            INSERT
            INTO key_word(lib_id, word)
            VALUES (#lib_id#, #word:VARCHAR#)
            <selectKey resultClass="int" keyProperty="id">
                select last_insert_id() limit 1
            </selectKey>
        </insert>
     
     <update id="update" parameterClass="Word">
      UPDATE key_word
      SET lib_id = #lib_id#, word = #word:VARCHAR#
      WHERE id = #id#
     </update>
     
     <select id="query" parameterClass="int" resultClass="Word">
      SELECT id, lib_id, word
      FROM key_word
      WHERE  id = #id#
     </select>
     
     <delete id="del" parameterClass="int" >
      DELETE
      FROM key_word
      WHERE  id = #id#
     </delete>
    </sqlMap>

        ibatis的分红置文件里都以sql语句。

        至此,那八个框架的搭建达成。

    SpringMVC总结篇  http://www.linuxidc.com/Linux/2016-06/132659.htm

    Spring+SpringMVC公司赶快支付架构搭建  http://www.linuxidc.com/Linux/2015-09/122942.htm

    SpringMVC的乱码管理  http://www.linuxidc.com/Linux/2015-07/120542.htm

    Spring MVC+Spring3+Hibernate4开垦境遇搭建 http://www.linuxidc.com/Linux/2013-07/87119.htm 

    Spring MVC整合Freemarker基于阐明情势 http://www.linuxidc.com/Linux/2013-02/79660.htm 

    依靠评释的Spring MVC简要介绍 http://www.linuxidc.com/Linux/2012-02/54896.htm

    SpringMVC详细示例实战教程 http://www.linuxidc.com/Linux/2015-06/118461.htm

    Spring MVC 框架搭建及详明 http://www.linuxidc.com/Linux/2012-01/52740.htm

    SpringMVC 至极管理  http://www.linuxidc.com/Linux/2015-06/119049.htm

    本文永恒更新链接地址:http://www.linuxidc.com/Linux/2016-10/135846.htm

    图片 6

    本文由澳门402永利com发布于关于计算机,转载请注明出处:框架搭建,mybatis集成配置

    关键词:

上一篇:总是返回Null

下一篇:没有了