程序功能描述:在页面上点击一个“Disable Account”按钮,后台实现Disable某个账号,程序原理如下:
- 首先在页面上点击按钮,该按钮的ID是“disableAccountBtn”,找出页面加载的JS文件,在文件中搜索出该ID,发现如下代码:
$('#disableAccountBtn').click(function() { $('#promptWinYes').unbind('click').click(function() { $('#promptWin').dialog('close'); $.getJSON(DISABLE_USER_ACTION, { uid : clientId }, function(data) { switchButtonVisible(false); showAlertWin('Warning', DISABLE_USER_CALLBACK_MSG); }); }); showPromptWin('Warning', DISABLE_USER_MSG); });
其中$.getJSON来调用并获取远程的JSON字符串,将其转换为JSON对象,如果成功,则执行回调函数,再从JS中查找DISABLE_USER_ACTION="../disableUser.action. 可见这个调用最终执行了
../disableUser.action?uid=userID这个service -
查找后台JAVA代码,在UserManagementController.java中找到如下方法:
@RequestMapping("/disableUser.action") public ModelAndView disableUser(HttpServletRequest request) throws Exception { return WorkflowController.disableClient(request, clientAction); }
此处用的是Spring MVC的框架,这个方法用到了clientAction
-
再进入WorkflowController.disableClient(request, clientAction)
public static ModelAndView disableClient(HttpServletRequest httpReq, ClientAction clientAction) { String clientId = httpReq.getParameter("uid"); UserBean sales = resolveSales(httpReq); String methodId = "{" + sales.getId() + "," + clientId + "," + System.currentTimeMillis() + "}"; logger.info("/disableUser.action BEGIN " + methodId); boolean success = true; String errorMsg = null; try { clientAction.disableClient(clientId, sales); } catch (Throwable e) { logger.error("Failed to disable user " + methodId, e); success = false; errorMsg = "Server Internal Error. Please contact the system Admin."; } finally { logger.info("/disableUser.action END " + methodId); } ModelMap model = new ModelMap(); model.addAttribute("success", success); model.addAttribute("errorMsg", errorMsg); return new ModelAndView("results", model); }
可见,这个service执行成功后,返回的字符串是{"errorMsg":null,"success":true}
-
进入clientAction.disableClient(clientId, sales)方法,ClientAction里面有很多方法:
/** * Action to disable an existing client. * * @param clientId * @param currentUser * @throws Exception */ public void disableClient(String clientId, UserBean currentUser) throws Exception { umUserService.createESFDataIfMissing(clientId); UserProfile oldUser = umUserService.getUserProfile(clientId); disableClient(currentUser, oldUser); }
-
再进入dsiableClient:
void disableClient(UserBean salesUserBean, UserProfile clientUserProfile) throws Exception { if (salesUserBean == null || clientUserProfile == null) { return; } String clientId = clientUserProfile.getUid(); String clientName = clientUserProfile.getDisplayName(); UserRequestEntity userEntity = new UserRequestEntity(); userEntity.setTitle(UMTConstants.USER_PROFILE_TITLE + "(Disable)"); userEntity.setClientId(clientId); userEntity.setClientName(clientName); userEntity.setSalesId(salesUserBean.getId()); userEntity.setSalesName(salesUserBean.getName()); //restore old user profile try { userEntity.setProfile(JsonUtil.write(clientUserProfile)); } catch (Exception e) { logger.error("Failed to encode user profile into JSON.", e); } umWorkflow.startDisableClientWorkflow(userEntity, UMTConstants.WF_DISABLE_CLIENT); }
-
最后调用通用的startDisableClientWorkflow()方法:
/** * Start the workflow to disable an existing client. * * @param userEntity the user profile provided by front-end, cannot be null */ public void startDisableClientWorkflow(UserRequestEntity userEntity, String workflowName) throws Exception { //1) save records into request tables UserRequestEntityHelper.validatePV(userEntity); UMRequestEntity umEntity = requestTracker.save(userEntity); Long requestId = umEntity.getId(); logger.info("Saved request entity of [disable] for {" + userEntity.getClientId() + "} as " + requestId); //2) update request status umEntity.setStatus(UMRequestEntity.Status.ESF_DISABLE); startWorkflow(requestId, workflowName, umEntity); }
startWorkflow():/** * Start workflow for request. * * @param requestId * @param workflowName * @param umEntity * @throws Exception */ public void startWorkflow(Long requestId, String workflowName, UMRequestEntity umEntity) throws Exception { logger.info("Start workflow " + workflowName + " for request [" + requestId + "]"); //1) get workflow and start the process instance UMWorkflowBean workflowBean = workflowRepository.findUMWorkflowByName(workflowName); String processId = workflowService.startProcessInstance(workflowBean.getProcessName(), new HashMap<String, String>()); //2) update request status if (umEntity == null) { umEntity = new UMRequestEntity(); umEntity.setStatus(UserRequestEntity.Status.PROCESSING); umEntity.setStatusFlag(0); } umEntity.setId(requestId); umEntity.setWorkflowId(workflowBean.getWorkflowId()); umEntity.setProcessId(processId); requestTracker.update(umEntity); logger.info("Started workflow for request [" + requestId + "]"); //3) transit to first state Set<String> nextStates = workflowService.findActiveStates(processId); StateHandler nextStateHandler = null; for (String nextState : nextStates) { nextStateHandler = handlerRepository.getByState(nextState); if (nextStateHandler != null) { break; } } if (nextStateHandler != null) { nextStateHandler.execute(requestId); } } }
-
找到WorkFlowService的实现类对应的方法:
/** * Start the process instance. * */ public String startProcessInstance(String processKey, Map<String, String> variables) { ProcessInstance processInstance = executionService.startProcessInstanceByKey(processKey, variables); return processInstance.getId(); }
ExecutionService这个类属于JBPM,全称是Java Business Process Management,是一种基于J2EE的轻量级工作流管理系统。
总结:这类AJAX+Spring MVC的程序基本原理就是前台JS代码去调用后台的Service.测试的时候打开Fidder或者Firebug就能捕捉到具体的service已经传递的参数
接下去是真证的Disable逻辑:
-
在ESFServiceImpl里有一个disableUser()方法:
public void disableUser(String operator, String userId) throws Exception { // Map<String, String> userESFAttrMap = queryUserESFInfo(userId); // if (userESFAttrMap == null) { // throw new Exception("Disable user error. Can not find user: " // + userId); // } // if (ESFConstans.STATUS_ENABLED.equals(userESFAttrMap // .get(ESFConstans.CLIENT_USERS_ATTR.STATUS))) { // changeUserStatus(operator, userId); // } Connection con = null; CallableStatement st = null; ResultSet rs = null; try { con = getConnection(); st = con.prepareCall(ESFConstans.CALL_DISABLE_USER); st.setString(1, userId); st.setString(2, operator); st.execute(); } catch (SQLException e) { throw e; } catch (Exception e) { throw e; } finally { closeAllDBResources(rs, st, con); } }
其中使用CallableStatement调用了存储过程ESFConstans.CALL_DISABLE_USER:public static final String CALL_DISABLE_USER = "call " + schema + "cdc_rules_gmo_serve." + profix + "set_status_v2(?,0,?)";
相关推荐
Spring + Hibernate + Spring mvc +Ajax 整合 框架,一个简单的添加删除。
后台通过自定义注解结合一个访问拦截器实现整个系统的权限控制 04. 系统前台采用全采用的Html+jQuery开发 05. 系统前台与后台的交互全部使用 Ajax 异步请求 06. 自定义 SecureValid 注解实现权限的控制 07. ...
【项目原型】spring+spring mvc+mybatis+shiro+maven+bootstrap+ajax+json+分页+逆向工程 包含现在最流行的技术框架,快速部署各种应用,加入shiro权限框架,安全,美观,你值得拥有
三期答辩课程设计,人事管理系统Mybatis+Spring+Spring MVC框架整合AJAX+JQuery实现登录、注册以及验证码和验证注册用户信息,包括数据库备份,课设说明,答辩PPT,Windows下sts(eclipse) 。
Spring+SpringMVC+Mybatis+Maven+bootstrap+ajax+jQuery整合开发简单的员工后台管理系统,免责声明,朋友分享,切勿商用
OA项目,使用SSM框架开发,使用EASYUI前端AJAX的JSON传值实现,对数据进行合理封装。
基于hibernate + spring + spring mvc + bootstrap的管理系统实现;有任何不懂的技术问题都可以联系我共同讨论
项目描述 它是一个针对汽车销售有关的后台管理...spring+spring mvc+mybatis+bootstrap+jquery 数据库文件 链接:https://pan.baidu.com/s/1qWF4Nx3xGjjtW3fW-pjRDg 提取码:nfwj jar包文件 压缩包WEB-INF/lib下
Maven+Spring MVC +Hibernate Validate(服务端验证) 增删改 ajax请求 文件上传
spring+spring-mvc+mybatis+bootstrap+ajax详细项目案例
NULL 博文链接:https://xkorey.iteye.com/blog/726146
此资源为我个人毕业设计系统,商城系统源码,包含数据库设计,系统分析,技术(Spring MVC AOP)+MyBatis+Ajax+JavaScript
bootstrap,ajax,spring mvc,spring,hibernate 项目实战源码
前端技术:Layui,Ajax,Json 后端技术:SpringBoot,MyBatis 本系统共分为两个角色:管理员和用户。 主要功能有: 前台: 车位查询、车位预约、公告展示、个人信息管理、留言、订单查看等。 后台: 信息发布管理、...
一个实用了spring mvc和ajax异步请求的例子
文件上传demo:前台ajax,后台spring mvc,效率好于传统表单上传。
个人认为相当适合入门和知识巩固!! 一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc DispatcherServlet说明 ...二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
springmvc+maven+hibernate+ajax+分页多表下的整合demo