ssm框架基础配置

阅读更多
s-s-m整合(spring springmvc mabatis) 参考

1.导入所需的jar包
2.配置web.xml文件
  2.1   spring 的监听
  2.2   springmvc前端控制器
  2.3   spring 解决中文乱码的过滤器
  等
3.配置三大框架的配置文件
  3.1 applicationContext.xml  (spring)
  3.2 spring-servlet.xml    (springmvc)
  3.3 mybatis-config.xml (mybatis)


4. jdbc.properties 配置文件    这里数据源链接使用的c3p0

web.xml的基本配置
注意了:配置文件一定要和web.xml中的配置名字一样

 
       contextConfigLocation
       classpath:applicationContext.xml
 


 
    org.springframework.web.context.ContextLoaderListener
 

 
 
    spring
    org.springframework.web.servlet.DispatcherServlet
   
        contextConfigLocation
        classpath:spring-servlet.xml
   

    1
 

 
    spring
    /
 

 
   
        characterEncodingFilter 
        org.springframework.web.filter.CharacterEncodingFilter 
         
            encoding 
            UTF-8 
       
 
         
            forceEncoding 
            true 
       
 
   
 
     
        characterEncodingFilter 
        /* 
   


以下为三打框架的配置文件参考
*******************************************************************************************************************
1. applicationContext.xml

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="  
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

   
   

   
              class="com.mchange.v2.c3p0.ComboPooledDataSource">
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
   

   
   
            scope="singleton">
       
       
   

   
   
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       
   


   
   
       
       
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
           
       

   


   
   
   
                    expression="execution(* com.xxxx.xxx.service..*.*(..))" />
       

   



   
   
   
   
       
   

   
   
   
       
       
   



*********************************************************************************************************************
2.spring-servlet.xml

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:aop="http://www.springframework.org/schema/aop"  
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="   
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd 
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd 
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

   
   
       
        
        
   

   
   
   
   
   
   
   
   
   
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       
       
   

   
   
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
       
           
               
                                    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
           

       

   

   
   
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
       
           
               
                                    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
           

       

   

   
   
            class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
        p:maxUploadSize="34564356345456"
        p:defaultEncoding="utf-8">
       
   

   
   
   
           
           
           
           
       


******************************************************************************************************************
3.mybatis-config.xml

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">


   
     
         
       
       
       
       
   

   
   
       
       
   
 
      
   
       
   

   

***************************************************************************************************************
4. jdbc.properties 配置文件(可以直接写在spring的配置文件中)
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://192.168.1.1:3306/shoppingdb
datasource.username=root
datasource.password=123456
c3p0.acquireIncrement=3
c3p0.initialPoolSize=3
c3p0.idleConnectionTestPeriod=60
c3p0.minPoolSize=5
c3p0.maxPoolSize=100
c3p0.maxStatements=100
c3p0.numHelperThreads=10
c3p0.maxIdleTime=60
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
mybatis 貌似是没有级联操作
这里分享个技巧
jdbc.properties中的url地址最后加上allowMultiQueries=true
url=jdbc:mysql://192.168.1.1:3306/liubao2?useUnicode=true&characterencoding=utf8&allowMultiQueries=true

让mysql驱动默认开启批量操作
然后就可以这样写了
   
        delete from photos where xid=#{id};
        delete from photoalbum where xid=#{id}
   

这样就可以同时执行两条sql语句了
*****************************************************************************************************************
其实都是细节性的问题,细节决定成败!!!
--奋斗中的刘阿宝

你可能感兴趣的:(spring,mvc,mysql,框架,ssm)