您好,欢迎访问三七文档
struts2.2.3+spring3.1.0+mybatis3.1.0集成简单demo分类:java2012-03-2516:5311171人阅读评论(30)收藏举报strutsspringuserintegerstringencodingstruts2.2.3+spring3.1.0+mybatis3.1.0集成简单demo项目下载地址:主要实现用户的增删改查操作1、导入相应的jar包2、配置web.xml主要是配置struts2和springweb.xml文件内容如下:[html]viewplaincopy?xmlversion=1.0encoding=UTF-8?web-appversion=2.5xmlns=xmlns:xsi=xsi:schemaLocation=welcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-list!--加载spring的配置文件--listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!--配置spring配置文件加载的位置--context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:beans.xml/param-value/context-param!--配置struts2--filterfilter-namestruts2/filter-namefilter-classorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter/filter-class/filterfilter-mappingfilter-namestruts2/filter-nameurl-pattern/*/url-pattern/filter-mapping/web-app3、配置spring配置文件,主要包括配置数据源、事务、mybaits等beans.xml配置文件详细如下:[html]viewplaincopy?xmlversion=1.0encoding=UTF-8?beansxmlns=xmlns:xsi=xmlns:context=xmlns:aop=xmlns:tx=xsi:schemaLocation=!--采用注释的方式配置bean--context:annotation-config/!--配置要扫描的包--context:component-scanbase-package=com.pdsu.edu/context:component-scan!--proxy-target-class=true强制使用cglib代理如果为false则spring会自动选择--aop:aspectj-autoproxyproxy-target-class=true/!--数据库配置文件位置--context:property-placeholderlocation=classpath:jdbc.properties/!--配置dbcp数据源--beanid=dataSourceclass=org.apache.commons.dbcp.BasicDataSourcedestroy-method=closepropertyname=driverClassNamevalue=${jdbc.driverClassName}/propertyname=urlvalue=${jdbc.url}/propertyname=usernamevalue=${jdbc.username}/propertyname=passwordvalue=${jdbc.password}/!--队列中的最小等待数--propertyname=minIdlevalue=${jdbc.minIdle}/property!--队列中的最大等待数--propertyname=maxIdlevalue=${jdbc.maxIdle}/property!--最长等待时间,单位毫秒--propertyname=maxWaitvalue=${jdbc.maxWait}/property!--最大活跃数--propertyname=maxActivevalue=${jdbc.maxActive}/propertypropertyname=initialSizevalue=${jdbc.initialSize}/property/bean!--配置mybitasSqlSessionFactoryBean--beanid=sqlSessionFactoryclass=org.mybatis.spring.SqlSessionFactoryBeanpropertyname=dataSourceref=dataSource/propertyname=configLocationvalue=classpath:mybatis.xml/property/bean!--配置SqlSessionTemplate--beanid=sqlSessionTemplateclass=org.mybatis.spring.SqlSessionTemplateconstructor-argname=sqlSessionFactoryref=sqlSessionFactory//bean!--事务配置--beanid=transactionManagerclass=org.springframework.jdbc.datasource.DataSourceTransactionManagerpropertyname=dataSourceref=dataSource//bean!--使用annotation注解方式配置事务--tx:annotation-driventransaction-manager=transactionManager//beans4.JDBC配置文件详细[plain]viewplaincopyjdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/operationLogjdbc.username=rootjdbc.password=jdbc.maxActive=2jdbc.maxIdle=5jdbc.minIdle=1jdbc.initialSize=3jdbc.maxWait=30005、配置mybatis主配置文件:[html]viewplaincopy?xmlversion=1.0encoding=UTF-8?!DOCTYPEconfigurationPUBLIC-//mybatis.org//DTDConfig3.0//ENconfigurationtypeAliasestypeAliasalias=usertype=com.pdsu.edu.domain.User//typeAliasesmappersmapperresource=com/pdsu/edu/domain/sqlMappers/user.xml//mappers/configuration6、配置user.xml文件[html]viewplaincopy?xmlversion=1.0encoding=utf-8?!DOCTYPEmapperPUBLIC-//mybatis.org//DTDMapper3.0//ENmappernamespace=com.pdsu.edu.domain.UserresultMaptype=com.pdsu.edu.domain.Userid=userResultresultproperty=idcolumn=idjdbcType=INTEGERjavaType=java.lang.Integer/resultproperty=usernamecolumn=username/resultproperty=passwordcolumn=password//resultMapselectid=userLoginparameterType=userresultMap=userResultselect*fromuserwhereusername=#{username}andpassword=#{password}
本文标题:struts2.2.3 + spring3.1.0 + mybatis3.1.0集成简单demo
链接地址:https://www.777doc.com/doc-3364157 .html