Spring3 MVC 教程 (Mybatis+ExtJS基本权限管理)

jopen 13年前
     Spring3 MVC 教程 (Mybatis+ExtJS基本权限管理)    <br /> 说明:    <br />    <br />    <ul>     <li>验证码:采用开源的https://code.google.com/p/kaptcha/,代码自己修改了部分。</li>     <li>上传文件:swfupload,参考论坛里面的另外一个帖子。</li>     <li><strong>ext的tab非iframe模式,只加载一次ExtJS,速度还可以~自己命名jsp里面的变量的时候注意变量ID不要重复 </strong>参加下面部分js代码</li>     <li>框架采用了mybatis+spring3MVC,应该说是学习springmvc的好例子。代码都有详细注释。</li>     <li>js的加载采用了yepnope,是一个基于条件的异步资源(JS和CSS)加载工具</li>     <li>mybatis的配置文件的生成采用了自己修改的mybatis的工具。<a href="/misc/goto?guid=4959500713337109868" target="_blank">mybatis-generator 修改版</a> </li>     <br />    </ul>    <br />    <br /> 其他:    <br /> 附件为maven构建的工程,需要lib的可以去网盘下载,里面也有base_power.pdm文件,可以自己转为mysql的脚本。    <br /> 建库语句在war包里面的readme文件夹下面    <br /> 7z的分卷压缩老是搞不好,只好贴网盘地址了    <br />    <a href="/misc/goto?guid=4959500713532979011" target="_blank">http://dl.dbank.com/c0bakwliui</a>    <pre class="brush:javascript; toolbar: true; auto-links: false;">// tab主面板 index.tabPanel = new Ext.TabPanel({     id: 'mainTabPanel',     region: 'center',     activeTab: 0,     deferredRender: false,     enableTabScroll: true,     // bodyStyle:'height:100%',     defaults: {         layout: 'fit',         autoScroll: true     },     plugins: new Ext.ux.TabCloseMenu({         closeTabText: '关闭标签页',         closeOtherTabsText: '关闭其他标签页',         closeAllTabsText: '关闭所有标签页'     }),     items: [{         id: 'home',         title: '我的主页',         iconCls: 'home',         closable: false,         autoScroll: true,         autoLoad: {             url: index.welcome,             scripts: true,             nocache: true         }     }],     listeners: {         'bodyresize': function (panel, neww, newh) {             // 自动调整tab下面的panel的大小             var tab = panel.getActiveTab();             var centerpanel = Ext.getCmp(tab.id + "_div_panel");             if (centerpanel) {                 centerpanel.setHeight(newh - 2);                 centerpanel.setWidth(neww - 2);             }         }     } });</pre>    <pre class="brush:javascript; toolbar: true; auto-links: false;"><%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@ include file="/WEB-INF/views/commons/taglibs.jsp"%> <div id="changePwdDiv" style="width: 100%; height: 100%;">  <div id="changePwdToolBarDiv"></div>  <div id="changePwdFormDiv"></div> </div>  <script type="text/javascript"> $(document).ready(function() {  //yepnope("${ctx}/resources/js/user/changepwd.js");  Ext.ns("Ext.Authority.changepassword"); // 自定义一个命名空间  changepwd = Ext.Authority.changepassword; // 定义命名空间的别名  changepwd = {   changeurl : ctx + "/user/changepwd"  };  // 编辑用户Form  changepwd.changePwdFormPanel = new Ext.form.FormPanel({   renderTo : 'changePwdFormDiv',   border : false,   defaults : {    xtype : "textfield",    labelWidth : 50   },   bodyStyle : 'padding:5px;background-color:transparent;',   items : [ {// 原密码    id : 'old_password',    name : 'old_password',    inputType : "password",    fieldLabel : '原密码',    anchor : '99%',    allowBlank : false,    maxLength : 32   }, { // 新密码    id : 'new_password',    name : 'new_password',    inputType : "password",    fieldLabel : '新密码',    anchor : '99%',    allowBlank : false,    maxLength : 32   }, {// 确认密码    id : 'compare_password',    name : 'compare_password',    inputType : "password",    fieldLabel : '确认密码',    vtype : "password",// 自定义的验证类型    vtypeText : "两次输入的密码不一致!",    confirmTo : "new_password",// 要比较的另外一个的组件的id    anchor : '99%',    allowBlank : false,    maxLength : 32   }, {// 账户ID    xtype : 'hidden',    name : 'userId',    value : '${user.userId}'   } ]  });  // 工具栏  changepwd.changePwdToolbar = new Ext.Toolbar({   renderTo : 'changePwdToolBarDiv',   items : [ new Ext.Button({    text : '保存',    iconCls : 'save',    handler : function() {     var form = changepwd.changePwdFormPanel.getForm();     if (form.isValid()) {      var values = form.getValues();      // 发送请求      Share.AjaxRequest({       url : changepwd.changeurl,       params : {        oldPassword : Ext.MD5(values.old_password),        newPassword : Ext.MD5(values.new_password),        comparePassword : Ext.MD5(values.compare_password),        userId : values.userId       },       callback : function(json) {        // 重新登录        Share.getWin().location = ctx;       },       falseFun : function(json) {//失败后想做的个性化操作函数        if (json.msg.indexOf('原密码不正确!请重新输入') > -1) {         $("#old_password").focus().val('');         return;        }        if (json.msg.indexOf('两次输入的新密码不一致') > -1) {         $("#new_password").val('');         $("#compare_password").val('').focus();         return;        }        if (json.msg.indexOf('请输入正确的帐号和其注册邮箱') > -1) {         return;        }       }      });     }    }   }), new Ext.Button({    text : '取消',    iconCls : 'cancel',    handler : function() {     header.changePwdWindow.close();    }   }) ]  });  var events = "beforecopy beforepaste beforedrag contextmenu selectstart drag paste copy cut dragenter";  $("#old_password").bind(events, function(e) {   if (e && e.preventDefault)    e.preventDefault();   else    window.event.returnValue = false;   return false;  });  $("#new_password").bind(events, function(e) {   return false;  });  $("#compare_password").bind(events, function(e) {   return false;  }); }); </script></pre>    <pre class="brush:xml; toolbar: true; auto-links: false;"><?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:mvc="http://www.springframework.org/schema/mvc"  xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"  xsi:schemaLocation="  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"  default-lazy-init="true">   <!-- 只搜索@Controller 标注的类 不搜索其他标注的类 -->  <context:component-scan base-package="com.chenxin.authority" use-default-filters="false">   <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />  </context:component-scan>   <!-- controller层的属性和配置文件读入 ,多个用逗号隔开 <context:property-placeholder location="classpath:/config/others/config.properties" /> -->   <!-- 应用属性文件读入 -->  <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">   <property name="ignoreResourceNotFound" value="true" />   <property name="locations">    <list>     <!-- 标准配置 -->     <value>classpath:/config/others/config.properties</value>     <value>classpath:/config/ibatis/jdbc.properties</value>    </list>   </property>  </bean>   <!-- 用于持有applicationProperties,将properties转变为静态方法使用,PropertiesHolder.getProperty("somekey") -->  <bean class="com.chenxin.authority.common.utils.PropertiesHolder">   <property name="properties" ref="applicationProperties" />  </bean>   <!-- PropertyPlaceholderConfigurer,用于spring ${placeholder}的解析 -->  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">   <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />   <property name="properties" ref="applicationProperties" />  </bean>   <!-- 激活 @Required @Autowired,JSR 250's @PostConstruct, @PreDestroy and @Resource 等标注 -->  <context:annotation-config />    <!-- 对某些静态资源,如css,图片等进行过滤 ,有引用 "/resources/**" 的路径引用转到工程的/resources/目录取资源 -->  <!-- <mvc:resources mapping="/favicon.ico" location="/favicon.ico"/> -->  <mvc:resources mapping="/resources/**" location="/resources/" />   <!-- 简单的地址映射 -->  <!-- Forwards requests to the "/" resource to the "welcome" view    <mvc:view-controller path="/admin" view-name="/admin/login" />   -->    <mvc:annotation-driven />  <!-- Configures support for @Controllers <mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping  和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。  如果不用这个,则要声明下面2个bean  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">         <property name="messageConverters">             <list>              <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">                <property name="supportedMediaTypes" value="application/json"/>              </bean>             </list>         </property>     </bean>   -->   <!--  <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">    拦截器注册 -->   <!-- <property name="interceptors">    <bean class="com.company.project.common.springmvc.interceptor.SharedRenderVariableInterceptor"/>   </property>   </bean>   -->      <!-- jsp视图 -->  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">   <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />   <property name="prefix" value="/WEB-INF/views/" />   <property name="suffix" value=".jsp" />  </bean>   <!-- 针对类、方法级别的权限拦截器 -->  <mvc:interceptors>   <mvc:interceptor>    <!-- <mvc:mapping path="/fileupload" /> -->    <mvc:mapping path="/main*" />    <mvc:mapping path="/header*" />    <mvc:mapping path="/welcome*" />    <mvc:mapping path="/treeMenu*" />    <mvc:mapping path="/role**/**" />    <mvc:mapping path="/user**/**" />    <mvc:mapping path="/module**/**" />    <mvc:mapping path="/field**/**" />    <bean class="com.chenxin.authority.web.interseptor.LoginInterceptor"></bean>   </mvc:interceptor>  </mvc:interceptors>   <!--开发期间注释掉,上线后启用 错误解析器 发生错误默认会跳转到/web-inf/views/timeout.jsp -->  <!-- <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="defaultErrorView"    value="timeout" /> <property name="exceptionMappings"> <props> <prop key="java.sql.SQLException">timeout</prop> <prop key="java.lang.RuntimeException">timeout</prop>    <prop key="org.springframework.transaction.TransactionException">timeout</prop> <prop key="org.springframework.dao.DataAccessException">timeout</prop>    </props> </property> </bean> -->   <!-- 国际化,并且可以批定文件编码,可以使用classpath: 或者WEB-INF/ 前缀 -->  <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">   <property name="basenames">    <list>     <value>classpath:/config/others/messages</value>     <value>classpath:ValidationMessages</value>    </list>   </property>   <property name="defaultEncoding" value="UTF-8" />   <property name="cacheSeconds" value="60" />  </bean>   <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />   <!-- 文件上传 -->  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">   <!-- 解析request的编码 ,Default is ISO-8859-1 -->   <property name="defaultEncoding" value="UTF-8" />   <!-- 设置最大允许的大小(字节)。-1表示没有限制(默认) 1024*1024*10=10MB -->   <property name="maxUploadSize" value="1048576000" />   <!--被允许的最大的内存的大小,Default is 10240 bytes -->   <property name="maxInMemorySize" value="20480" />   <!-- 一个类似懒加载的属性.可以定义该属性.让解析文件的时候再抛异常,然后Controller中定义异常处理的方法 -->   <property name="resolveLazily" value="true" />  </bean> </beans></pre>代码不多贴了,上图片吧。    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/f7af85f024f1dc8ee7abe8448ef963c2.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/1e36b6c1322b60119e73f4d36efe22ea.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/3b523a00737e2e097a453c37dad46a60.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/ee5acc23f4b2aff842dbc7d935d0cdde.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/f789317b893809316b9d89223b4b2d0e.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/229c413d7b694e9cbd26df8825771c87.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/05c83014e5d63cd087c378a62151d0c4.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/df25628a7fcddff649a7ee808d12f172.jpg" />    <br />    <img style="width:705px;height:466px;" border="0" alt="" src="https://simg.open-open.com/show/76605373d15a9574004013f859f86874.jpg" />    <br />    <img title="rar.png" src="https://simg.open-open.com/show/42a8c3e06b0df6f814686984be88c6b4.png" />     <a title="authority.rar" href="/misc/goto?guid=4959500713617983141">authority.rar</a>    <br />    <br /> 转自:    <a href="/misc/goto?guid=4959500713696756259" target="_blank">http://www.iteye.com/topic/1119744</a>    <br />