您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 园林工程 > spring+springmvc+ibatis整合注解方式实例
1.需求说明实现用户通过数据库验证登录需求,采用Myeclipse+Tomcat6.0+Mysql5.0+JDK1.62.数据库表开发所用是Mysql数据库,只建立单张用户表T_USER,表结构如下:字段名称数据类型字段描述IDint用户编号USERNAMEVARCHAR用户名PASSWORDVARCHAR用户登录密码sql语句如下:CREATETABLE`t_user`(`ID`int(11)NOTNULLauto_increment,`USERNAME`varchar(255)defaultNULL,`PASSWORD`varchar(255)defaultNULL,PRIMARYKEY(`ID`));3.构建源代码目录4.用到的jar包(见附件Archive.rar)5.各项Xml配置文件详解(1)web.xml文件(Tomcat使用)服务器根据配置内容初始化spring框架,springmvc框架和log4j日志框架?xmlversion=1.0encoding=UTF-8?web-appversion=2.5xmlns=:xsi=:schemaLocation=://java.sun.com/xml/ns/javaee/web-app_2_5.xsd!--应用程序名称--display-nameISS/display-name!--应用程序描述说明性文字--descriptionSpring,SpringMvc,Ibatis/description!--ServletContext初始化参数--context-paramparam-namewebAppRootKey/param-nameparam-valuespring_springmvc_ibatis.root/param-value/context-paramcontext-paramparam-namelog4jConfigLocation/param-nameparam-value/WEB-INF/classes/log4j.properties/param-value/context-paramcontext-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/classes/applicationContext.xml/param-value/context-param!--字符过滤,防止添加到数据库的数据为乱码--filterfilter-namecharacterEncodingFilter/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueUTF-8/param-value/init-paraminit-paramparam-nameforceEncoding/param-nameparam-valuetrue/param-value/init-param/filterfilter-mappingfilter-namecharacterEncodingFilter/filter-nameurl-pattern/*/url-pattern/filter-mapping!--web权限配置--filterfilter-namespringSecurityFilterChain/filter-namefilter-classorg.springframework.web.filter.DelegatingFilterProxy/filter-class/filterfilter-mappingfilter-namespringSecurityFilterChain/filter-nameurl-pattern/*/url-pattern/filter-mapping!--配置监听器,用于初始化--listenerlistener-classorg.springframework.web.util.Log4jConfigListener/listener-class/listenerlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!--Servlet初始化参数,配置springmvc模块--servletservlet-namespringmvc/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/classes/springmvc-servlet.xml/param-value/init-paramload-on-startup2/load-on-startup/servletservlet-mappingservlet-namespringmvc/servlet-nameurl-pattern//url-pattern/servlet-mapping!--配置session存在时间--session-configsession-timeout60/session-timeout/session-config!--默认起始页面--welcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-list!--异常跳转页面--error-pageexception-typejava.lang.Exception/exception-typelocation/WEB-INF/jsp/exception.jsp/location/error-page/web-app(2)springmvc-servlet.xml(Springmvc框架配置文件)该文件是springmvc框架配置文件,也是它的核心文件?xmlversion=1.0encoding=UTF-8?beansxmlns=:xsi=:mvc=:context=:schemaLocation=://://://://://!--自动扫描,完成bean创建和依赖注入--context:component-scanbase-package=com.archie/!--启动SpringMVC的注解功能,完成请求和注解POJO的映射--beanclass=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter/!--视图解析器--beanid=viewResolverclass=org.springframework.web.servlet.view.InternalResourceViewResolverpropertyname=viewClassvalue=org.springframework.web.servlet.view.JstlView/propertyname=prefixvalue=/WEB-INF/views//propertyname=suffixvalue=.jsp//bean!--异常解析器--beanid=simpleMappingExceptionResolverclass=org.springframework.web.servlet.handler.SimpleMappingExceptionResolverpropertyname=exceptionMappingspropspropkey=org.springframework.web.multipart.MaxUploadSizeExceededExceptioncommon/fileerror/prop/props/property/bean/beans(3)applicationContext.xml(Spring框架配置文件)?xmlversion=1.0encoding=UTF-8?beansxmlns=:xsi=:mvc=:context=:aop=:tx=:schemaLocation=://://://://
本文标题:spring+springmvc+ibatis整合注解方式实例
链接地址:https://www.777doc.com/doc-5317510 .html