使用Jquery miniui插件写的一个管理员对员工的操作(二)
来源:互联网 发布:淘宝免费申请试用在哪 编辑:程序博客网 时间:2024/05/17 01:48
Action类package cn.jxc.ssm.action;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.UUID;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.commons.io.FileUtils;import org.apache.struts2.ServletActionContext;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import cn.jxc.ssm.po.TDept;import cn.jxc.ssm.po.TEmployee;import cn.jxc.ssm.po.TEmployeeExtend;import cn.jxc.ssm.service.TDeptService;import cn.jxc.ssm.service.TEmployeeService;@Controller@Scope("prototype")public class TEmployeeAction implements ServletRequestAware,ServletResponseAware{@Resourceprivate TEmployeeService tEmployeeService;@Resourceprivate TDeptService tDeptService;private TEmployee record;HttpServletRequest request;HttpServletResponse response;//查询全部员工public void all() throws IOException{ String key = request.getParameter("key");//获取查询条件 //分页 int pageIndex = 0; if(request.getParameter("pageIndex")!=null){ pageIndex = Integer.parseInt(request.getParameter("pageIndex")); } int pageSize = 10; if(request.getParameter("pageSize")!=null){ pageSize = Integer.parseInt(request.getParameter("pageSize")); } int start = pageIndex * pageSize, end = start + pageSize; response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); List<TEmployeeExtend> listTEmployeeExtend = new ArrayList<TEmployeeExtend>(); listTEmployeeExtend = tEmployeeService.selectByTEmployeeName(key); List<TEmployeeExtend> listT = new ArrayList<TEmployeeExtend>(); for(int i=0,l=listTEmployeeExtend.size();i<l;i++){ if(i>=start&&i<end){ listT.add(listTEmployeeExtend.get(i)); } } JSONArray jsArray = JSONArray.fromObject(listT); String json = jsArray.toString(); System.out.println(json+"<-------"); String sq = "{"+"total:"+listTEmployeeExtend.size()+","+"data:"+json+"}"; System.out.println(sq); response.getWriter().write(sq);}//修改员工信息public void GetEmployee() throws IOException{response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); String id = request.getParameter("id");TEmployee te = tEmployeeService.selectByPrimaryKey(Integer.parseInt(id));JSONObject json = JSONObject.fromObject(te);String str = json.toString();response.getWriter().write(str);}public String updateEmployee() { String json = request.getParameter("data"); JSONArray array = JSONArray.fromObject(json);//先读取串数组 Object[] o = array.toArray();//转成对像数组 JSONObject obj = JSONObject.fromObject(o[0]); //将json串转换成数组后,再将数组转换成对象 record = (TEmployee) obj.toBean(obj, TEmployee.class); //将上传文件放在upload\\目录下 String oldPath = null; oldPath = record.getImage();if(oldPath.equals(null)||oldPath.equals("")){record.setImage(tEmployeeService.selectByPrimaryKey(record.getId()).getImage());tEmployeeService.updateByPrimaryKeySelective(record);}else{ String fileName = copyFile(oldPath); record.setImage("upload\\"+fileName); tEmployeeService.updateByPrimaryKeySelective(record); }return "updateEmployeeOk";}//删除员工public String deleteEmployee(){String idStr = request.getParameter("id");String[] ids = idStr.split(","); for (int i = 0, l = ids.length; i < l; i++) { int id = Integer.parseInt(ids[i]); tEmployeeService.deleteByPrimaryKey(id); }return "deleteOk";}//插入员工(使用json进行处理)public String insert(){ String json = request.getParameter("data"); JSONArray array = JSONArray.fromObject(json);//先读取串数组 Object[] o = array.toArray();//转成对像数组 JSONObject obj = JSONObject.fromObject(o[0]); //将json串转换成数组后,再将数组转换成对象 record = (TEmployee) obj.toBean(obj, TEmployee.class); //将上传文件放在tomcat服务器下jxc\\upload\\目录下 String oldPath = record.getImage(); String fileName = copyFile(oldPath); record.setImage("upload\\"+fileName); tEmployeeService.insert(record); return "insertOk";}//查询部门使用JSON传数据public void selectDeptAll() throws IOException{response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); List<TDept> listDept = new ArrayList<TDept>();listDept = tDeptService.selectByExample(null);JSONArray jsArray = JSONArray.fromObject(listDept);String json = jsArray.toString();response.getWriter().write(json);}//拷贝文件public String copyFile(String oldPath) { File oldfile = new File(oldPath); String path = ServletActionContext.getServletContext().getRealPath("/upload"); //根据路径名创建一个文件 File file = new File(path); //判断file是否存在,如果不存在,则自动创建一个 if(!file.exists()){ file.mkdirs(); } //将上传的文件进行从新命名 String newFile = null; newFile= UUID.randomUUID() + oldfile.getName().substring(oldfile.getName().indexOf(".")); //将上传文件放入到新的目录下 try {FileUtils.copyFile(oldfile, new File(file, newFile));} catch (IOException e) {e.printStackTrace();} return newFile;} public TEmployee getRecord() {return record;}public void setRecord(TEmployee record) {this.record = record;}//setsetServletRequest方法实现ServletRequestAware接口public void setServletRequest(HttpServletRequest request) {this.request = request;}//setServletResponse方法实现ServletResponseAware方法public void setServletResponse(HttpServletResponse response) {this.response = response;}}
0 0
- 使用Jquery miniui插件写的一个管理员对员工的操作(二)
- 使用Jquery miniui插件写的一个管理员对员工的操作
- 使用Jquery miniui插件写的一个管理员对员工的操作(三)
- jQuery MiniUI 表格的使用
- jquery miniui的体验
- 初学miniui之miniui的使用
- 用Jquery写的一个分页插件
- 如何写一个简单的jquery插件
- 如何写一个Jquery 的Plugin插件
- 如何写一个简单的jQuery插件
- 一个jquery对table的操作
- jquery miniUi使用小结
- jquery miniUi使用小结
- jQuery miniUI 使用实例
- jquery miniUi使用小结
- jquery写的一个表格合并单元格的插件
- jQuery 之 (二)事件操作、jq对文档的操作、属性选择器使用
- 一个离职员工对中兴的回望
- [排序不等式] Codeforces 717C Bubble Cup 9 - Finals C. Potions Homework
- 优化Hybrid app的原生支持
- android使用startActivityForResult时,requestCode和resultCode的作用
- linux VS Windows
- hdu 5869 Different GCD Subarray Query
- 使用Jquery miniui插件写的一个管理员对员工的操作(二)
- HDU 5875 Function (思路题目)
- [矩阵快速幂加速DP] Codeforces 717D Bubble Cup 9 - Finals D. Dexterina’s Lab
- C++引用的基本概念与应用
- [随机化 构造] Codeforces 717H Bubble Cup 9 - Finals H. Pokermon League challenge
- 数据库系统概论之第二章关系数据库
- [构造] Codeforces 717E Bubble Cup 9 - Finals E. Paint it really, really dark gray
- 51nod 1212 无向图最小生成树
- 2016.09.10【初中部 NOIP普及组 】模拟赛题解