
1.配置的目录2.jar 包链接https://pan.baidu.com/s/1ghkw7lx 密码9x8z3.配置文件管理mybatiessqlMapConfig.xml?xml version1.0 encodingUTF-8 ?!DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttp://mybatis.org/dtd/mybatis-3-config.dtd!-- 全局的seetting的配置 --configuration!-- 定义别名 --typeAliases!-- 批量别名的定义 用于resultType指定包名 自动定义别名 也就是类名多个包 多个packge--package namecn.sjzc.pojo/!-- package namecn.sjzc.pojo/ --/typeAliases/configurationapplicationContext-dao.xmlbeans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aop xmlns:txhttp://www.springframework.org/schema/txxmlns:taskhttp://www.springframework.org/schema/taskxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsdhttp://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.2.xsd!-- 加载db.properties --context:property-placeholder locationclasspath:db.properties /!-- 数据源 --bean iddataSource classorg.apache.commons.dbcp.BasicDataSourcedestroy-methodcloseproperty namedriverClassName value${jdbc.driver} /property nameurl value${jdbc.url} /property nameusername value${jdbc.username} /property namepassword value${jdbc.password} /!-- 初始化连接大小 --property nameinitialSize value${jdbc.initialSize}/property!-- 连接池最大数量 --property namemaxActive value${jdbc.maxActive}/property!-- 连接池最大空闲 --property namemaxIdle value${jdbc.maxIdle}/property!-- 连接池最小空闲 --property nameminIdle value${jdbc.minIdle}/property!-- 获取连接最大等待时间 --property namemaxWait value${jdbc.maxWait}/property/bean!-- sqlSessionFactory --bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBean!-- 数据库连接池 --property namedataSource refdataSource/property!-- 加载mybatis的全局配置文件/ssm/config/mybaties/sqlMapConfig.xml --property nameconfigLocation valueclasspath:mybaties/sqlMapConfig.xml/property/bean!-- 扫描包路径如果扫描多个包中间使用半角逗号分隔启用注解--!-- mapper扫描器 --bean classorg.mybatis.spring.mapper.MapperScannerConfigurer!--com.wqrg.yz.zs.admissionspicture.mapper多个包的的话 加 , 分隔开--property namebasePackage valuecn.sjzc.mapper/propertyproperty namesqlSessionFactoryBeanName valuesqlSessionFactory/property/bean/beans管理serviceapplicationContext-service.xmlbeans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aop xmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsd !-- 定义商品管理的service --!-- bean iditemService classsn.sjzc.service.impl.ItemServiceImpl/bean --!-- context:component-scanbase-packagecom.wqrg.yz.fw.*.service,com.wqrg.yz.zs.*.service,com.wqrg.yz.weixin.service/context:component-scan --context:component-scan base-packagecn.sjzc.service/context:component-scan/beansapplicationContext-transaction.xml管理事务beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aop xmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsd !-- 事务管理器对mybaties操作事务的控制,spring使用jdbc的事务控制类--bean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManager!-- 在applicationContext-dao.xml配置了 数据源--property namedataSource refdataSource/property/bean!-- 通知 --tx:advice idtxAdvice transaction-managertransactionManagertx:attributes!-- 传播行为 --tx:method namesave* propagationREQUIRED/tx:method namedelete* propagationREQUIRED/tx:method nameupdate* propagationREQUIRED/tx:method nameinsert* propagationREQUIRED/tx:method namefind* propagationSUPPORTS read-onlytrue/tx:method nameget* propagationSUPPORTS read-onlytrue/tx:method nameselect* propagationSUPPORTS read-onlytrue//tx:attributes/tx:advice!-- aop --aop:configaop:advisor advice-reftxAdvice pointcutexecution(* cn.sjzc.service.impl.*.*(..))//aop:config/beansspringmvc.xml管理springbeans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aop xmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.2.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.2.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.2.xsd !-- handler扫描 扫描controller --!-- context:component-scan base-packagecom.wqrg.yz.fw.*.controller,com.wqrg.yz.zs.*.controller,com.wqrg.yz.weixin.controller/ --context:component-scan base-packagecn.sjzc.controller/context:component-scan!-- 注解映射器和注解适配器配置 --!-- mvc:annotation-driven/mvc:annotation-driven --!--conversion-service 是自定义的的注解起 --!-- mvc:annotation-driven conversion-serviceconversionService/ --!-- 配置校验在 注解器适配器里边 注入 数据转换自定义参数的绑定--mvc:annotation-driven validatorvalidator conversion-serviceconversionService/!-- 自定义的参数的绑定 需要配置 映射器的转换 --bean idconversionService classorg.springframework.format.support.FormattingConversionServiceFactoryBeanproperty nameconverterslistbean classcn.sjzc.controller.converter.DateConvert/bean!--多个的话在下边自己的定义继续加载bean classcom.wqrg.yz.converter.CustomDateConverter/bean--/list/property/bean!-- 校验器 --bean idvalidator classorg.springframework.validation.beanvalidation.LocalValidatorFactoryBeanproperty nameproviderClass valueorg.hibernate.validator.HibernateValidator/property!-- 配置信息的配置文件 --property namevalidationMessageSource refmessageSource/property/bean!-- 校验错误信息配置文件 --bean idmessageSourceclassorg.springframework.context.support.ReloadableResourceBundleMessageSource!-- 资源文件名--property namebasenameslistvalueclasspath:ValidationMessages/value/list/property!-- 资源文件编码格式 --property namefileEncodings valueutf-8 /!-- 对资源文件内容缓存时间单位秒 --property namecacheSeconds value120 //bean!-- 全局异常处理只要是实现了HandlerExceptionResolver 就是全局的 异常的处理器如果有多个的类只会实现一个--bean classcn.sjzc.exception.HandelException/!-- 视图解析器 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolver!-- 视图解析器配置jsp路径的前缀和后缀 --property nameprefix value/WEB-INF/jsp//propertyproperty namesuffix value.jsp/property/bean!-- 上传文件 --bean idmultipartResolver classorg.springframework.web.multipart.commons.CommonsMultipartResolver!-- 设置上传图片最大为5M --property namemaxUploadSizevalue5242880/value/property/bean!-- 静态资源解析包括 js、css、img、..--mvc:default-servlet-handler/!--mvc:resources location/js/ mapping/js/**/mvc:resources location/res/images/ mapping/images/**/mvc:resources location/weixinanon/ mapping/weixinanon/**/--!--拦截器 --!-- 多个拦截器顺序的执行path/**/ 拦截所有的--mvc:interceptorsmvc:interceptormvc:mapping path/**/bean classcn.sjzc.controller.intercept.Intercept1/bean/mvc:interceptormvc:interceptormvc:mapping path/**/bean classcn.sjzc.controller.intercept.Intercept2/bean/mvc:interceptor/mvc:interceptors/beansdb.properties管理数据库# 方便外部的操作来读写文件#jdbc.driveroracle.jdbc.driver.OracleDriver#jdbc.urljdbc:oracle:thin:localhost:1521:orcljdbc.drivercom.mysql.jdbc.Driverjdbc.urljdbc:mysql://localhost:3306/mybatiesjdbc.usernamerootjdbc.passwordrootjdbc.initialSize0#定义最大连接数jdbc.maxActive20#定义最大空闲jdbc.maxIdle20#定义最小空闲jdbc.minIdle1#定义最长等待时间jdbc.maxWait60000log4j.properties日志#在开发环境下的 设置成 DEBUG 生产环境设置成 info 或者errorlog4j.rootLoggerDEBUG, stdout#log4j.logger.org.mybatisDEBUGlog4j.appender.stdoutorg.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layoutorg.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern%5p %d %C: %m%n验证的信息 (可以没有)ValidationMessages.propertiesweb.xml?xml version1.0 encodingUTF-8?web-app xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlnshttp://java.sun.com/xml/ns/javaee xmlns:webhttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd idWebApp_ID version2.5display-namessm/display-namewelcome-file-listwelcome-fileindex.html/welcome-filewelcome-fileindex.htm/welcome-filewelcome-fileindex.jsp/welcome-filewelcome-filedefault.html/welcome-filewelcome-filedefault.htm/welcome-filewelcome-filedefault.jsp/welcome-file/welcome-file-listservlet-mappingservlet-namedefault/servlet-nameurl-pattern*.js/url-patternurl-pattern*.css/url-patternurl-pattern/assets/*quot;/url-patternurl-pattern/images/*/url-pattern/servlet-mappingcontext-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring/applicationContext-*.xml/param-value/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerservletservlet-namespringmvc/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring/springmvc.xml/param-value/init-param/servletservlet-mappingservlet-namespringmvc/servlet-nameurl-pattern*.action/url-pattern/servlet-mappingservletservlet-namespringmvc_rest/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:spring/springmvc.xml/param-value/init-param/servletservlet-mappingservlet-namespringmvc_rest/servlet-nameurl-pattern//url-pattern/servlet-mappingfilterfilter-nameCharacterEncodingFilter/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueutf-8/param-value/init-param/filterfilter-mappingfilter-nameCharacterEncodingFilter/filter-nameurl-pattern/*/url-pattern/filter-mapping/web-app4. 写例子controllerservicemapperItemMapper.xml?xml version1.0 encodingUTF-8 ?!DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd!-- 配置mapper --mapper namespacecn.sjzc.mapper.ItemMapperItemMapper.javapublic interface ItemMapper {public ListItemExte selItemlist(ItemQueryVo queryVo)throws Exception;public Item selItemByid(int id)throws Exception;public void delItemByid(int id)throws Exception;}