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中的配置名字一样
<!-- spring监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- spring解决中文乱码的过滤器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以下为三打框架的配置文件参考
*******************************************************************************************************************
1. applicationContext.xml
<?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: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">
<!-- Properties文件读取配置,base的properties -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- data source -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${datasource.driverClassName}"></property>
<property name="jdbcUrl" value="${datasource.url}"></property>
<property name="user" value="${datasource.username}"></property>
<property name="password" value="${datasource.password}"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property>
<!-- JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements" value="${c3p0.maxStatements}"></property>
<!-- c3p0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能 通过
多线程实现多个操作同时被执行。Default: 3-->
<property name="numHelperThreads" value="${c3p0.numHelperThreads}"></property>
</bean>
<!-- 定义 SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
scope="singleton">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置事务通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务传播属性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="select*" propagation="REQUIRED" read-only="true" />
<tx:method name="query*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.xxxx.xxx.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<!-- Mybatis-Spring 会自动为我们注册Mapper对应的MapperFactoryBean对象 -->
<!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
<!-- 给所有的dao接口自动添加实现类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxxx.xxx.dao" />
</bean>
<!-- 自动扫描组件,这里要把controler下面的 controller去除,他们是在springmvc的配置文件中配置的,如果不去除会影响事务管理的。 -->
<context:component-scan base-package="com.xxxx.ssm">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
*********************************************************************************************************************
2.spring-servlet.xml
<?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: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">
<!-- 扫描包 -->
<context:component-scan base-package="com.wskj.ssm">
<!-- 扫描所有的controller 但是不扫描service-->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- 启用注解 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 静态资源映射 -->
<mvc:resources location="/resource/" mapping="/static/**"></mvc:resources>
<mvc:resources location="/files/" mapping="/files/**"></mvc:resources>
<!-- 页面解析器。prefix:前缀, suffix:后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- json的支持 -->
<bean id="messageAdapter"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<!-- Support JSON -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<bean id="exceptionMessageAdapter"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
<property name="messageConverters">
<list>
<!-- Support JSON -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="34564356345456"
p:defaultEncoding="utf-8">
<!-- <property name="defaultEncoding" value="utf-8"></property> -->
</bean>
<!-- 配置springmvc的拦截器 -->
<!-- <mvc:interceptors>
<mvc:interceptor> -->
<!-- 设置要拦截的url地址 -->
<!-- <mvc:mapping path="/**"/> -->
<!-- 设置不拦截的url -->
<!-- <mvc:exclude-mapping path="/login.do"/>
<mvc:exclude-mapping path="/static/**"/>
--><!-- 设置拦截器 -->
<!-- <bean class="com.wskj.ssm.interceptors.LoginInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors> -->
</beans>
******************************************************************************************************************
3.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 参数-->
<settings>
<!-- changes from the defaults -->
<setting name="cacheEnabled" value="false" />
<setting name="useGeneratedKeys" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<!--这里给实体类取别名,方便在mapper配置文件中使用-->
<package name="com.xxxx.xxx.pojo"/>
</typeAliases>
<!--自动加载mapper配置文件 -->
<mappers>
<package name="com.xxxx.xxx.dao"/>
</mappers>
</configuration>
***************************************************************************************************************
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 id="deletephotoalbumbyid" parameterType="java.lang.Integer">
delete from photos where xid=#{id};
delete from photoalbum where xid=#{id}
</delete>
这样就可以同时执行两条sql语句了
*****************************************************************************************************************
其实都是细节性的问题,细节决定成败!!!
--奋斗中的刘阿宝
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中的配置名字一样
<!-- spring监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- spring解决中文乱码的过滤器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
以下为三打框架的配置文件参考
*******************************************************************************************************************
1. applicationContext.xml
<?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: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">
<!-- Properties文件读取配置,base的properties -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- data source -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${datasource.driverClassName}"></property>
<property name="jdbcUrl" value="${datasource.url}"></property>
<property name="user" value="${datasource.username}"></property>
<property name="password" value="${datasource.password}"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}"></property>
<!-- JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements" value="${c3p0.maxStatements}"></property>
<!-- c3p0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能 通过
多线程实现多个操作同时被执行。Default: 3-->
<property name="numHelperThreads" value="${c3p0.numHelperThreads}"></property>
</bean>
<!-- 定义 SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
scope="singleton">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置事务通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务传播属性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="select*" propagation="REQUIRED" read-only="true" />
<tx:method name="query*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.xxxx.xxx.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<!-- Mybatis-Spring 会自动为我们注册Mapper对应的MapperFactoryBean对象 -->
<!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
<!-- 给所有的dao接口自动添加实现类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxxx.xxx.dao" />
</bean>
<!-- 自动扫描组件,这里要把controler下面的 controller去除,他们是在springmvc的配置文件中配置的,如果不去除会影响事务管理的。 -->
<context:component-scan base-package="com.xxxx.ssm">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
*********************************************************************************************************************
2.spring-servlet.xml
<?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: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">
<!-- 扫描包 -->
<context:component-scan base-package="com.wskj.ssm">
<!-- 扫描所有的controller 但是不扫描service-->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- 启用注解 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 静态资源映射 -->
<mvc:resources location="/resource/" mapping="/static/**"></mvc:resources>
<mvc:resources location="/files/" mapping="/files/**"></mvc:resources>
<!-- 页面解析器。prefix:前缀, suffix:后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- json的支持 -->
<bean id="messageAdapter"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<!-- Support JSON -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<bean id="exceptionMessageAdapter"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
<property name="messageConverters">
<list>
<!-- Support JSON -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="34564356345456"
p:defaultEncoding="utf-8">
<!-- <property name="defaultEncoding" value="utf-8"></property> -->
</bean>
<!-- 配置springmvc的拦截器 -->
<!-- <mvc:interceptors>
<mvc:interceptor> -->
<!-- 设置要拦截的url地址 -->
<!-- <mvc:mapping path="/**"/> -->
<!-- 设置不拦截的url -->
<!-- <mvc:exclude-mapping path="/login.do"/>
<mvc:exclude-mapping path="/static/**"/>
--><!-- 设置拦截器 -->
<!-- <bean class="com.wskj.ssm.interceptors.LoginInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors> -->
</beans>
******************************************************************************************************************
3.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 参数-->
<settings>
<!-- changes from the defaults -->
<setting name="cacheEnabled" value="false" />
<setting name="useGeneratedKeys" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<!--这里给实体类取别名,方便在mapper配置文件中使用-->
<package name="com.xxxx.xxx.pojo"/>
</typeAliases>
<!--自动加载mapper配置文件 -->
<mappers>
<package name="com.xxxx.xxx.dao"/>
</mappers>
</configuration>
***************************************************************************************************************
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 id="deletephotoalbumbyid" parameterType="java.lang.Integer">
delete from photos where xid=#{id};
delete from photoalbum where xid=#{id}
</delete>
这样就可以同时执行两条sql语句了
*****************************************************************************************************************
其实都是细节性的问题,细节决定成败!!!
--奋斗中的刘阿宝
发表评论
-
java springcloud
2018-01-03 10:49 409这里我简单的写了个demo springcloud 是基于sp ... -
elaticserach ik自定义远程词库的方法
2017-08-07 11:10 1681这是ik的配置文件 在配置远程扩展字典写上下面方法的接口(要 ... -
最简单的单例模式
2017-02-23 17:09 507这里假设有一个实体类Goods,有gname字段 那么单 ... -
BaseDao
2017-02-21 19:04 207//刚开始的时候用的这个 public class Ba ... -
使用artdialog模态对话框实现新增等功能
2017-02-21 16:05 5661.首先把整个artdialog的文件夹丢到项目中去 ... -
使用JAX-WS发布web服务
2017-02-20 12:59 544服务提供者 1.添加一个服务接口 public int ...
相关推荐
ssm框架基础配置文件,不需要自己每次都手动敲,拿来即用,注意修改少数几个路径,超级方便。
ssm框架配置简要说明,一些必要的文档说明, 懂SSM框架基础的适合观看一下
ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。...
Java开发项目基于SSM框架的管理系统源代码。基于SSM框架的管理系统 实现 登录 、 注册 、 增 、 删 、 改 、 查 ; 可继续完善增加前端、校验、其他功能等; 可作为SSM项目开发练习基础模型; 课程设计 、 毕业...
适合使用SSM框架开发的人群,可以在此基础上进行添加功能等,将SSM配置都已经弄好。
SSM-xml+注解整合SSM框架-《员工信息管理系统》-功能演示.mp4 ...主要利用xml配置问价+注解整合SSM框架,在此基础上实现一套crud。 前端没有使用模板,所以大道至简,主要是联系ssm框架的整合方法。
spring+spring mvc +mybatis 整合maven工程
ssm框架的基本模型,包括一些配置文件,还有接口、实现类,并且都有详细的注释
适合初学者,SSM框架基础的搭建和最简单的配置文件,没有工具包跟拦截器,只是单纯的框架。
ssm项目基础框架搭建,包括maven配置、spring、springMvc、mybatis、logging等基础内容、xml配置注释详细
基础的ssm框架整合配置,实现简单的crud功能,对新手有帮助
1711A 六组项目简介(仓库管理系统) 我们做的是一个仓库管理系统,它包含:菜单管理、基础...配置:项目用的是maven+ssm框架+httpclient+webservice+mongodb+redis缓存技术,需要配置相应的配置文件,才可以运行此文件
使用此资源的好处:我们都知道搭建SSM项目最麻烦的就是前期进行框架的搭建,配置很麻烦很繁琐,人称配置地狱,这个模板可以为你省去大量的搭建时间,不过这其中的内容是一个很基础的项目,没有大量的功能,只有简单...
按部就班地学习:建议从基础的Java Web开发开始,逐步深入到SSM框架的学习。通过实践,逐步掌握SSM框架的使用技巧和Java Web开发的最佳实践。 参考项目文件和笔记:项目文件和笔记提供了丰富的背景信息和开发经验。...
项目标题:基于SSM框架的Java CRUD操作演示源码 ...本项目以简洁明了的代码展示了SSM框架在实现后端CRUD操作的基础应用,适合作为学习SSM框架的经典入门示例,也便于开发者在此基础上进行扩展和优化。
适合对SSM没有使用过的同学,讲解通俗易懂,覆盖了当前SSM使用的基本操作 课程内容: 1、Spring简介及快速入门 2、Spring配置文件及其相应API 3、Spring注解开发 4、Spring web环境及其Junit的集成 5、Spring ...
- Properties配置文件:4个,包含系统的基础配置信息。 - JPG图片:3个,用于界面美化和视觉辅助。 简而言之,这是一个基于SSM框架开发的宿舍管理系统,不仅界面友好、操作便捷,而且能够高效地处理宿舍相关的各项...
webservice里面的框架技术 cxf生成一个沟通接口的桥梁,然后新建一个沟通桥梁的类,再通过配置相关的配置文件及jar包就可以调用出接口中的数据,之后选中一条数据,并输入收件人的邮箱 ,点击发送后,我们会将收件人...
一、项目简介 ...基础数据管理:客户资料管理,系统基础数据配置,维修项目管理,供应商管理,配件信息管理,仓库信息管理,业务类型管理等 https://blog.csdn.net/weixin_43860634/article/details/125337823
按部就班地学习:建议从基础的Java Web开发开始,逐步深入到SSM框架的学习。通过实践,逐步掌握SSM框架的使用技巧和Java Web开发的最佳实践。 参考项目文件和笔记:项目文件和笔记提供了丰富的背景信息和开发经验。...