标签:
String cmd=request.getParameter("c"); ApplicationContext spring = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext()); JdbcTemplate jdbc=spring.getBean("jdbcTemplate",JdbcTemplate.class); UserBean userBean=(UserBean)session.getAttribute(Constants.SESSION_USER); Map<String,Object> ret=new HashMap<String,Object>(); ret.put("success", true); ret.put("code", 1); ret.put("message", "操作成功"); java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMM"); if("getJobList".equals(cmd)){ List<Map<String,Object>> list=jdbc.queryForList(sql); for(Map<String,Object> map:list){ String c=colors[random.nextInt(colors.length)]; map.put("bordercolor", c); map.put("bgcolor", c); } out.println(JSON.toJSONString(list)); }else if("drop".equals(cmd)){ String id=request.getParameter("id"); String stime=request.getParameter("stime"); String etime=request.getParameter("etime"); jdbc.update("update toa_onduty set stime=?,etime=? where id=?",stime,etime,id); out.println(JSON.toJSONString(ret)); }else if("editable".equals(cmd)){ String stime=request.getParameter("stime"); String etime=request.getParameter("etime"); //ret.put("editable",gridService.isEditAble(userBean.getId(), stime, etime)); out.println(JSON.toJSONString(ret)); }else{ System.out.println("参数c的值["+cmd+"]有误,system/workflow/manager/handler.jsp"); out.println(JSON.toJSONString(ret)); }
view.jsp
function reload(id,type){ cache={id:id,type:type}; $("#calendar").fullCalendar(‘removeEvents‘); $.post(handlerJsp,{c:"getJobList",id:id,type:type},function(data){ if(data.length==0){lgxInfo("没有排班数据");}else{ alert("有"+data.length+"条排班记录"); } for(var i=0;i<data.length;i++) { var obj = new Object(); obj.id = data[i].id; obj.title = data[i].title; obj.start = parseDate( data[i].stime ); obj.end = parseDate( data[i].etime ); // obj.description = data[i].description; obj.backgroundColor=data[i].bgcolor; obj.borderColor=data[i].bordercolor; obj.allDay =false; // if(data[i].allday==1){ // obj.allDay =true; // }else{ // obj.allDay =false; // } $("#calendar").fullCalendar(‘renderEvent‘,obj,true); } },"JSON"); }
总体上我还是使用平台来开发;用平台来把控全局,只是在局部功能采用这样的写法。复杂的业务逻辑我也会面向接口编程写个Service,让Spring统一管理;
以这样的写法来方现一般的小操作,如行云流水、简单快捷。
标签:
原文地址:http://www.cnblogs.com/lingx/p/5613521.html