后台自己倒腾去
图片预览
Jsp页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'depart.jsp' starting page</title> 15 16 <meta http-equiv="pragma" content="no-cache"> 17 <meta http-equiv="cache-control" content="no-cache"> 18 <meta http-equiv="expires" content="0"> 19 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 20 <meta http-equiv="description" content="This is my page"> 21 <script type="text/javascript" 22 src="easyui/jquery-easyui-v1.5/jquery.min.js"></script> 23 <script type="text/javascript" 24 src="easyui/jquery-easyui-v1.5/jquery.easyui.min.js"></script> 25 <link href="easyui/jquery-easyui-v1.5/themes/icon.css" rel="stylesheet" 26 type="text/css" /> 27 <script type="text/javascript" 28 src="easyui/jquery-easyui-v1.5/locale/easyui-lang-zh_CN.js"></script> 29 <link href="easyui/jquery-easyui-v1.5/themes/default/easyui.css" 30 rel="stylesheet" type="text/css" /> 31 <script type="text/javascript" src='${pageContext.request.contextPath}/js/employee.js'> </script> 32 </head> 33 34 <body> 35 <table id='dg' style="text-align: center"></table> 36 <div id='tc' style="background-color: #EBEBEB"></div> 37 <table id='pc' style="width:300px" height="200px"></table> 38 </body> 39 </html>
JS代码
1 $(function() { 2 $('#dg').datagrid({ 3 url : 'EC/findAllEmployer.action', 4 rownumbers : true, 5 pagination : true, 6 fitColumns : true, 7 pageList : [ 5, 10, 15, 20 ], 8 columns : [ [ { 9 field : 'ID', 10 title : '工号', 11 width : 100, 12 align : 'center', 13 }, { 14 field : 'NAME', 15 title : '姓名', 16 width : 100, 17 align : 'center', 18 }, { 19 field : 'DEPT_ID', 20 title : '部门名称', 21 width : 100, 22 align : 'center', 23 }, { 24 field : 'JOB_ID', 25 title : '职位名称', 26 width : 100, 27 align : 'center', 28 }, { 29 field : 'CARD_ID', 30 title : '身份证号', 31 width : 100, 32 align : 'center', 33 }, { 34 field : 'ADDRESS', 35 title : '籍贯', 36 width : 100, 37 align : 'center', 38 }, { 39 field : 'PHONE', 40 title : '联系方式', 41 width : 100, 42 align : 'center', 43 }, ] ], 44 loadFilter : function(data) { 45 if (data.success == true) { 46 var data_ = { 47 "rows" : data.attributes.rows, 48 "total" : data.obj.totalSize, 49 }; 50 return data_; 51 } else { 52 $.messager.alert('警告', data.msg, 'info'); 53 54 } 55 ; 56 }, 57 }); 58 59 var editBoxing = undefined; 60 $('#dg') 61 .datagrid( 62 { 63 toolbar : [ 64 { 65 text : '新增', 66 iconCls : 'icon-edit', 67 handler : function() { 68 var jj = "<tr><td>工号:</td><td><input id='nid' class='easyui-textbox' editable='false' style='width:200px; value=''>"; 69 var str = "<div id='ddii' style='margin-top:20px' ><form id='ff' method='post'><table ><tr></tr>" 70 + "<tr><td>姓名:</td><td><input type='text' id='nname' name='name' style='width:200px;' class='easyui-validatebox' data-options='required:true' value='' >" 71 + "<tr><td>性别:</td><td>男<input type='radio' name='sex' checked='checked' value='男' > 女<input type='radio' name='sex' value='女' >" 72 + "<tr><td>部门名称:</td><td><input type='text' name='deptId' id='ndept' style='width:200px;' value='' >" 73 + "<tr><td>职位名称:</td><td><input type='text' name='jobId' id='njob' style='width:200px;' value='' >" 74 + "<tr><td>电话:</td><td><input type='text' id='nphone' name='phone' style='width:200px;' value='' >" 75 + "<tr><td>身份证号:</td><td><input type='text' id='ncard' name='cardId' style='width:200px;' value='' >" 76 + "<tr><td>学历:</td><td><input type='text' id='neducdtion' name='education' style='width:200px;' class='easyui-textbox' value='' >" 77 + "<tr><td>邮政:</td><td><input type='text' id='npostCode' name='postCode' style='width:200px;' class='easyui-textbox' value='' >" 78 + "<tr><td>生日:</td><td><input type='text' id='nbirthday' name='birthday' style='width:200px;' class='easyui-textbox' value='' >" 79 + "<tr><td>邮箱:</td><td><input type='text' id='nemail' name='email' style='width:200px;' class='easyui-validatebox' value='' >" 80 + "<tr><td>政治面貌:</td><td><input type='text' id='npolite' name='party' style='width:200px;' class='easyui-textbox' value='' >" 81 + "<tr><td>地址:</td><td><input type='text' id='nadress' name='address' style='width:200px;' class='easyui-validatebox' data-options='required:true' value='' >" 82 + "<tr><td>民族:</td><td><input id='nzu' name='race' style='width:200px; value=''>" 83 + "<tr><td>爱好:</td><td><input type='nhobby' name='hobby' id='nhobby' style='width:200px;' class='easyui-textbox' value='' >" 84 + "<tr><td>QQ号:</td><td><input type='nqq' name='qqNum' id='title' style='width:200px;' class='easyui-textbox' value='' >" 85 + "<tr><td>专业:</td><td><input type='nzhuanye' name='speciality' id='title' style='width:200px;' class='easyui-textbox' value='' >" 86 + "<tr><td>备注:</td><td><textarea width:400px height:100px' name='remark' style='background-color: #A9DC8D' id='remark' ></textarea>" 87 + "</td></tr><tr></tr><tr></tr><tr><td ><input type='reset' name='' style='width:70px;height:40px' class='easyui-linkbutton'></td><td style='text-align: right'><input type='button' style='width:70px;height:40px' class='easyui-linkbutton' value='提交' οnclick='tijiao2(1)'/></td></tr></table>" 88 + "</form></div>"; 89 parent.$("#dddd").dialog({ 90 title : '新增员工', 91 width : 400, 92 height : 650, 93 closed : false, 94 cache : false, 95 draggable : true, 96 content : str, 97 modal : true, 98 required : true, 99 }); 100 $('#dg').datagrid('reload'); 101 parent.$('#nname').validatebox({ 102 validType : 'loginnName' 103 }); 104 parent.$('#ndept').combobox({ 105 url : 'DC/CountAndDept.action', 106 valueField : 'ID', 107 textField : 'NAME', 108 panelHeight : 75, 109 required : true, 110 }); 111 parent.$('#njob').combobox({ 112 url : 'JC/countAndJob.action', 113 valueField : 'ID', 114 textField : 'NAME', 115 required : true, 116 }); 117 parent.$('#neducdtion').combobox({ 118 valueField : 'id', 119 textField : 'text', 120 required : true, 121 panelHeight : 75, 122 value : '本科及其以上', 123 data : [ { 124 id : '本科及其以上', 125 text : '本科及其以上' 126 }, { 127 id : '专科', 128 text : '专科' 129 }, { 130 id : '高中及其以下', 131 text : '高中及其以下' 132 } ] 133 }); 134 parent.$('#npolite').combobox({ 135 valueField : 'id', 136 textField : 'text', 137 panelHeight : 95, 138 value : '党员', 139 data : [ { 140 id : '党员', 141 text : '党员' 142 }, { 143 id : '群众', 144 text : '群众' 145 }, { 146 id : '团员', 147 text : '团员' 148 }, { 149 id : '民主党派', 150 text : '民主党派' 151 } ] 152 }); 153 parent.$('#nphone').validatebox({ 154 required : true, 155 validType : 'mobileAndTel' 156 }); 157 parent.$('#ncard').validatebox({ 158 required : true, 159 validType : 'idcard' 160 }); 161 parent.$('#nemail').validatebox({ 162 validType : 'email' 163 }); 164 165 } 166 }, 167 '-', 168 { 169 text : '删除', 170 iconCls : 'icon-remove', 171 handler : function() { 172 if (editBoxing != undefined) { 173 $.messager.alert('警告', "尚有正在编辑的记录"); 174 } else { 175 var array = $('#dg').datagrid( 176 'getSelections'); 177 if (array.length >= 1) { 178 var str = ''; 179 for (var i = 0; i < array.length; i++) { 180 str += array[i].ID + " "; 181 } 182 183 $ 184 .post( 185 'EC/deleteAEmployer.action', 186 { 187 str : str 188 }, 189 function(data) { 190 if (data.success == true) { 191 $('#dg') 192 .datagrid( 193 'reload'); 194 $.messager 195 .show({ 196 title : '更新消息', 197 msg : data.msg, 198 timeout : 3000 199 }); 200 $('#dg') 201 .datagrid( 202 'reload'); 203 } else { 204 $.messager 205 .alert( 206 '警告', 207 data.msg); 208 } 209 210 }); 211 } else { 212 $.messager.alert('警告', 213 "请至少选择一条记录删除"); 214 } 215 } 216 217 } 218 }, 219 '-', 220 { 221 text : '修改', 222 iconCls : 'icon-edit', 223 handler : function() { 224 var array = $('#dg').datagrid( 225 'getSelections'); 226 if (array.length == 1) { 227 show(2); 228 } 229 } 230 }, '-', { 231 text : '查看详细信息', 232 iconCls : 'icon-search', 233 handler : function() { 234 show(1); 235 } 236 }, '-', { 237 text : '刷新', 238 iconCls : 'icon-reload', 239 handler : function() { 240 $('#dg').datagrid('load'); 241 242 } 243 }, ], 244 }); 245 }); 246 247 String.prototype.replaceAll = function(findText, repText) { 248 var newRegExp = new RegExp(findText, 'gm'); 249 return this.replace(newRegExp, repText); 250 }; 251 252 function show(bb) { 253 var array = $('#dg').datagrid('getSelections'); 254 if (array.length == 1) { 255 $ 256 .post( 257 'EC/findEmployerById.action', 258 { 259 id : array[0].ID 260 }, 261 function(data) { 262 var jj = "<tr><td>工号:</td><td><input id='nid' name='id' readonly='readonly' class='easyui-textbox' editable='false' style='width:200px;' value='" 263 + data.id + "'>"; 264 var xbb = "<tr><td ><input type='reset' name='' style='width:70px;height:40px' class='easyui-linkbutton'></td><td style='text-align: right'><input type='button' style='width:70px;height:40px' class='easyui-linkbutton' value='提交' οnclick='tijiao2(2)'/></td></tr>"; 265 var str = "<div id='ddii' style='margin-top:20px' ><form id='ff' method='post'><table >" 266 + jj 267 + "<tr><td>姓名:</td><td><input type='text' readonly='readonly' id='nname' name='name' style='width:200px;' class='easyui-validatebox' data-options='required:true' value='" 268 + data.name 269 + "' >" 270 + "<tr><td>性别:</td><td>男<input type='radio' id='man' readonly='readonly' name='sex' value='男' > 女<input type='radio' id='woman' name='sex' value='女' >" 271 + "<tr><td>部门名称:</td><td><input type='text' readonly='readonly' name='deptId' id='ndept' style='width:200px;' value='" 272 + data.deptId 273 + "' >" 274 + "<tr><td>职位名称:</td><td><input type='text' readonly='readonly' name='jobId' id='njob' style='width:200px;' value='" 275 + data.jobId 276 + "' >" 277 + "<tr><td>电话:</td><td><input type='text' readonly='readonly' id='nphone' name='phone' style='width:200px;' value='" 278 + data.phone 279 + "' >" 280 + "<tr><td>身份证号:</td><td><input type='text' readonly='readonly' id='ncard' name='cardId' style='width:200px;' value='" 281 + data.cardId 282 + "' >" 283 + "<tr><td>学历:</td><td><input type='text' readonly='readonly' id='neducdtion' name='education' style='width:200px;' class='easyui-textbox' value='" 284 + data.education 285 + "' >" 286 + "<tr><td>邮政:</td><td><input type='text' readonly='readonly' id='npostCode' name='postCode' style='width:200px;' class='easyui-textbox' value='" 287 + data.postCode 288 + "' >" 289 + "<tr><td>生日:</td><td><input type='text' readonly='readonly' id='nbirthday' name='birthday' style='width:200px;' class='easyui-textbox' value='" 290 + data.birthday 291 + "' >" 292 + "<tr><td>邮箱:</td><td><input type='text' readonly='readonly' id='nemail' name='email' style='width:200px;' class='easyui-validatebox' value='" 293 + data.email 294 + "' >" 295 + "<tr><td>政治面貌:</td><td><input type='text' readonly='readonly' id='npolite' name='party' style='width:200px;' class='easyui-textbox' value='" 296 + data.party 297 + "' >" 298 + "<tr><td>地址:</td><td><input type='text' readonly='readonly' id='nadress' name='address' style='width:200px;' class='easyui-validatebox' data-options='required:true' value='" 299 + data.address 300 + "' >" 301 + "<tr><td>民族:</td><td><input id='nzu' readonly='readonly' name='race' style='width:200px; value='" 302 + data.race 303 + "'>" 304 + "<tr><td>爱好:</td><td><input type='nhobby' readonly='readonly' name='hobby' id='nhobby' style='width:200px;' class='easyui-textbox' value='" 305 + data.hobby 306 + "' >" 307 + "<tr><td>QQ号:</td><td><input type='nqq' readonly='readonly' name='qqNum' id='title' style='width:200px;' class='easyui-textbox' value='" 308 + data.qqNum 309 + "' >" 310 + "<tr><td>专业:</td><td><input type='nzhuanye' readonly='readonly' name='speciality' id='title' style='width:200px;' class='easyui-textbox' value='" 311 + data.speciality 312 + "' >" 313 + "<tr><td>备注:</td><td><textarea width:400px height:100px' readonly='readonly' name='remark' style='background-color: #A9DC8D' id='remark' >" 314 + data.remark 315 + "</textarea>" 316 + "</td></tr><tr></tr><tr></tr>" 317 + xbb 318 + "</table>" + "</form></div>"; 319 if (bb == '2') { 320 str = str.replaceAll("readonly='readonly'", ""); 321 parent.$("#dddd").dialog({ 322 title : '人员基本信息', 323 width : 500, 324 height : 630, 325 closed : false, 326 cache : false, 327 draggable : true, 328 content : str, 329 modal : true, 330 331 }); 332 parent.$('#nname').validatebox({ 333 validType : 'loginnName' 334 }); 335 parent.$('#ndept').combobox({ 336 url : 'DC/CountAndDept.action', 337 valueField : 'ID', 338 textField : 'NAME', 339 panelHeight : 75, 340 required : true, 341 }); 342 parent.$('#njob').combobox({ 343 url : 'JC/countAndJob.action', 344 valueField : 'ID', 345 textField : 'NAME', 346 required : true, 347 }); 348 parent.$('#neducdtion').combobox({ 349 valueField : 'id', 350 textField : 'text', 351 required : true, 352 panelHeight : 75, 353 value : '本科及其以上', 354 data : [ { 355 id : '本科及其以上', 356 text : '本科及其以上' 357 }, { 358 id : '专科', 359 text : '专科' 360 }, { 361 id : '高中及其以下', 362 text : '高中及其以下' 363 } ] 364 }); 365 parent.$('#npolite').combobox({ 366 valueField : 'id', 367 textField : 'text', 368 panelHeight : 95, 369 value : '党员', 370 data : [ { 371 id : '党员', 372 text : '党员' 373 }, { 374 id : '群众', 375 text : '群众' 376 }, { 377 id : '团员', 378 text : '团员' 379 }, { 380 id : '民主党派', 381 text : '民主党派' 382 } ] 383 }); 384 parent.$('#nphone').validatebox({ 385 required : true, 386 validType : 'mobileAndTel' 387 }); 388 parent.$('#ncard').validatebox({ 389 required : true, 390 validType : 'idcard' 391 }); 392 parent.$('#nemail').validatebox({ 393 validType : 'email' 394 }); 395 } 396 if (bb == '1') { 397 str = str.replace(xbb, " "); 398 399 parent.$("#dddd").dialog({ 400 title : '人员基本信息', 401 width : 500, 402 height : 630, 403 closed : false, 404 cache : false, 405 draggable : true, 406 content : str, 407 modal : true, 408 409 }); 410 if (parent.$('#man').val() == data.sex) { 411 parent.$('#man').attr('checked', 'checked'); 412 } else { 413 parent.$('#woman').attr('checked','checked'); 414 } 415 parent.$("#man,#woman").attr("disabled", true); 416 417 } 418 }); 419 420 } else { 421 $.messager.alert('警告', '请选择一条记录'); 422 } 423 424 };
Controller代码
1 package com.employee.controller; 2 3 import java.util.HashMap; 4 import java.util.List; 5 import java.util.Map; 6 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Qualifier; 9 import org.springframework.stereotype.Controller; 10 import org.springframework.web.bind.annotation.RequestMapping; 11 import org.springframework.web.bind.annotation.RequestMethod; 12 import org.springframework.web.bind.annotation.ResponseBody; 13 import org.springframework.web.servlet.ModelAndView; 14 15 import com.AjaxJson; 16 import com.DataResult; 17 import com.DouUtils; 18 import com.UtilsHelper; 19 import com.employee.po.EmployeeInf; 20 import com.employee.seriver.EmployeeSreiver; 21 22 @Controller 23 @RequestMapping("/EC") 24 public class EmployeeController { 25 @Autowired 26 @Qualifier("EmployeeSreiver") 27 private EmployeeSreiver EmployeeSreiver; 28 29 // 添加员工 30 @RequestMapping(value = "/addEmployer", method = RequestMethod.POST) 31 @ResponseBody 32 public AjaxJson addEmployer(Integer deptId, Integer jobId, String name, 33 String cardId, String address, String postCode, String tel, 34 String phone, String qqNum, String email, String sex, String party, 35 String birthday, String race, String education, String speciality, 36 String hobby, String remark) { 37 try { 38 EmployeeInf ne = new EmployeeInf(); 39 ne.setName(name); 40 ne.setDeptId(deptId); 41 ne.setJobId(jobId); 42 ne.setCardId(cardId); 43 ne.setParty(party); 44 ne.setPostCode(postCode); 45 ne.setAddress(address); 46 ne.setTel(tel); 47 ne.setPhone(phone); 48 ne.setQqNum(qqNum); 49 ne.setEmail(email); 50 ne.setSex(sex); 51 ne.setBirthday(birthday); 52 ne.setRace(race); 53 ne.setEducation(education); 54 ne.setSpeciality(speciality); 55 ne.setRemark(remark); 56 ne.setCreateDate(UtilsHelper.getDateFormatTime()); 57 int count = EmployeeSreiver.addEmployer(ne); 58 AjaxJson json = new AjaxJson(); 59 if (count > 0) { 60 json.setSuccess(true); 61 json.setMsg("新增成功"); 62 return json; 63 } else { 64 json.setSuccess(false); 65 json.setMsg("新增失败"); 66 return json; 67 } 68 } catch (Exception e) { 69 // TODO Auto-generated catch block 70 e.printStackTrace(); 71 AjaxJson json = new AjaxJson(); 72 json.setSuccess(false); 73 json.setMsg("系统错误"); 74 return json; 75 } 76 77 } 78 79 // 查询所有员工 80 @RequestMapping(value = "/findAllEmployer", method = RequestMethod.POST) 81 @ResponseBody 82 public AjaxJson findAllEmployer(int page, int rows) { 83 DataResult result = new DataResult(); 84 result.setPageSize(rows); 85 result.setStartLine((page - 1) * rows); 86 result.setTotalSize(EmployeeSreiver.findAllCount()); 87 List<Map<String, Object>> list = EmployeeSreiver 88 .findAllEmployer(result); 89 Map<String, Object> map = new HashMap<String, Object>(); 90 map.put("rows", list); 91 AjaxJson json = new AjaxJson(); 92 json.setSuccess(true); 93 json.setAttributes(map); 94 json.setObj(result); 95 return json; 96 } 97 98 // 根据员工姓名,省份证,电话,性别,职位,部门进行模糊查询 99 @RequestMapping(value = "/findAEmploter", method = RequestMethod.POST) 100 public ModelAndView findAEmploter(ModelAndView mv, EmployeeInf EmployeeInf) { 101 try { 102 EmployeeInf EmployeeInf1 = EmployeeSreiver 103 .findAEmploter(EmployeeInf); 104 mv.addObject("EmployeeInf", EmployeeInf1); 105 mv.setViewName("success1"); 106 return mv; 107 } catch (Exception e) { 108 // TODO Auto-generated catch block 109 e.printStackTrace(); 110 mv.setViewName("lost"); 111 return mv; 112 } 113 } 114 115 // 删除员工 116 @RequestMapping(value = "/deleteAEmployer", method = RequestMethod.POST) 117 @ResponseBody 118 public AjaxJson deleteAEmployer(String str) { 119 try { 120 List<Integer> list = DouUtils.splitStr(str); 121 int count = EmployeeSreiver.deleteEmployer(list); 122 AjaxJson json = new AjaxJson(); 123 if (count > 0) { 124 json.setSuccess(true); 125 json.setMsg("删除成功"); 126 return json; 127 } else { 128 json.setSuccess(false); 129 json.setMsg("删除失败"); 130 return json; 131 } 132 } catch (Exception e) { 133 // TODO Auto-generated catch block 134 e.printStackTrace(); 135 AjaxJson json = new AjaxJson(); 136 json.setSuccess(false); 137 json.setMsg("系统错误"); 138 return json; 139 } 140 } 141 142 // 修改员工 143 @RequestMapping(value = "/updateAEmployer", method = RequestMethod.POST) 144 @ResponseBody 145 public AjaxJson updateAEmployer(Integer id,Integer deptId, Integer jobId, String name, 146 String cardId, String address, String postCode, String tel, 147 String phone, String qqNum, String email, String sex, String party, 148 String birthday, String race, String education, String speciality, 149 String hobby, String remark) { 150 try { 151 EmployeeInf ne = new EmployeeInf(); 152 ne.setId(id); 153 ne.setName(name); 154 ne.setDeptId(deptId); 155 ne.setJobId(jobId); 156 ne.setCardId(cardId); 157 ne.setParty(party); 158 ne.setPostCode(postCode); 159 ne.setAddress(address); 160 ne.setTel(tel); 161 ne.setPhone(phone); 162 ne.setQqNum(qqNum); 163 ne.setEmail(email); 164 ne.setSex(sex); 165 ne.setBirthday(birthday); 166 ne.setRace(race); 167 ne.setEducation(education); 168 ne.setSpeciality(speciality); 169 ne.setRemark(remark); 170 AjaxJson json = new AjaxJson(); 171 int count=EmployeeSreiver.updateAEmployer(ne); 172 if(count==1){ 173 json.setSuccess(true); 174 json.setMsg("修改成功"); 175 return json; 176 }else{ 177 json.setSuccess(false); 178 json.setMsg("修改失败"); 179 return json; 180 } 181 } catch (Exception e) { 182 // TODO Auto-generated catch block 183 e.printStackTrace(); 184 AjaxJson json=new AjaxJson(); 185 json.setSuccess(false); 186 json.setMsg("插入失败"); 187 return json; 188 } 189 190 } 191 192 // 根据工号查询用户 193 @RequestMapping(value = "/findEmployerById", method = RequestMethod.POST) 194 @ResponseBody 195 public EmployeeInf findEmployerById(int id) { 196 return EmployeeSreiver.findAemployee(id); 197 } 198 199 }
ServiceImpl代码
1 package com.employee.seriver.impl; 2 3 import java.util.List; 4 import java.util.Map; 5 6 import javax.annotation.Resource; 7 8 import com.DataResult; 9 import com.employee.mapper.EmployeeInfMapper; 10 11 import org.springframework.stereotype.Service; 12 13 import com.employee.po.EmployeeInf; 14 import com.employee.seriver.EmployeeSreiver; 15 @Service("EmployeeSreiver") 16 public class EmployeeSreiverImpl implements EmployeeSreiver { 17 @Resource 18 private EmployeeInfMapper EmployeeInfMapper; 19 //添加员工 20 @Override 21 public int addEmployer(EmployeeInf EmployeeInf) { 22 return EmployeeInfMapper.addEmployer(EmployeeInf); 23 24 } 25 26 27 //根据员工姓名,省份证,电话,性别,职位,部门进行模糊查询 28 @Override 29 public EmployeeInf findAEmploter(EmployeeInf EmployeeInf) { 30 // TODO Auto-generated method stub 31 return EmployeeInfMapper.findAEmploter(EmployeeInf); 32 } 33 //删除员工 34 @Override 35 public int deleteEmployer(List<Integer> list) { 36 return EmployeeInfMapper.deleteEmployer(list); 37 38 } 39 //修改员工 40 @Override 41 public int updateAEmployer(EmployeeInf EmployeeInf) { 42 return EmployeeInfMapper.updateAEmployer(EmployeeInf); 43 44 } 45 //查询所有员工 46 @Override 47 public List<Map<String, Object>> findAllEmployer(DataResult result) { 48 // TODO Auto-generated method stub 49 return EmployeeInfMapper.findAllEmployer(result); 50 } 51 52 //查询总员工数 53 @Override 54 public int findAllCount() { 55 // TODO Auto-generated method stub 56 return EmployeeInfMapper.findAllCount(); 57 } 58 59 60 @Override 61 public EmployeeInf findAemployee(int id) { 62 // TODO Auto-generated method stub 63 return EmployeeInfMapper.findAemployee(id); 64 } 65 66 }
mapper 代码
package com.employee.mapper; import java.util.List; import java.util.Map; import com.DataResult; import com.employee.po.EmployeeInf; public interface EmployeeInfMapper { //添加员工 public int addEmployer(EmployeeInf EmployeeInf); //查询所有员工 public List<Map<String, Object>>findAllEmployer(DataResult result); //根据员工姓名,省份证,电话,性别,职位,部门进行模糊查询 public EmployeeInf findAEmploter(EmployeeInf EmployeeInf); //删除员工 public int deleteEmployer(List<Integer> list); //修改员工 public int updateAEmployer(EmployeeInf EmployeeInf); //查询总员工数 public int findAllCount(); //根据工号查询雇员详细信息 public EmployeeInf findAemployee(int id); }
mapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 3 <mapper namespace="com.employee.mapper.EmployeeInfMapper"> 4 <resultMap id="BaseResultMap" type="com.employee.po.EmployeeInf" > 5 <id column="ID" property="id" jdbcType="INTEGER" /> 6 <result column="DEPT_ID" property="deptId" jdbcType="INTEGER" /> 7 <result column="JOB_ID" property="jobId" jdbcType="INTEGER" /> 8 <result column="NAME" property="name" jdbcType="VARCHAR" /> 9 <result column="CARD_ID" property="cardId" jdbcType="VARCHAR" /> 10 <result column="ADDRESS" property="address" jdbcType="VARCHAR" /> 11 <result column="POST_CODE" property="postCode" jdbcType="VARCHAR" /> 12 <result column="TEL" property="tel" jdbcType="VARCHAR" /> 13 <result column="PHONE" property="phone" jdbcType="VARCHAR" /> 14 <result column="QQ_NUM" property="qqNum" jdbcType="VARCHAR" /> 15 <result column="EMAIL" property="email" jdbcType="VARCHAR" /> 16 <result column="SEX" property="sex" jdbcType="VARCHAR" /> 17 <result column="PARTY" property="party" jdbcType="VARCHAR" /> 18 <result column="BIRTHDAY" property="birthday" jdbcType="VARCHAR" /> 19 <result column="RACE" property="race" jdbcType="VARCHAR" /> 20 <result column="EDUCATION" property="education" jdbcType="VARCHAR" /> 21 <result column="SPECIALITY" property="speciality" jdbcType="VARCHAR" /> 22 <result column="HOBBY" property="hobby" jdbcType="VARCHAR" /> 23 <result column="REMARK" property="remark" jdbcType="VARCHAR" /> 24 <result column="CREATE_DATE" property="createDate" jdbcType="TIMESTAMP" /> 25 </resultMap> 26 <insert id="addEmployer" parameterType="com.employee.po.EmployeeInf"> 27 insert into employee_inf 28 <trim prefix="(" suffix=")" suffixOverrides=","> 29 <if test="id != null"> 30 ID, 31 </if> 32 <if test="deptId != null"> 33 DEPT_ID, 34 </if> 35 <if test="jobId != null"> 36 JOB_ID, 37 </if> 38 <if test="name != null"> 39 NAME, 40 </if> 41 <if test="cardId != null"> 42 CARD_ID, 43 </if> 44 <if test="address != null"> 45 ADDRESS, 46 </if> 47 <if test="postCode != null"> 48 POST_CODE, 49 </if> 50 <if test="tel != null"> 51 TEL, 52 </if> 53 <if test="phone != null"> 54 PHONE, 55 </if> 56 <if test="qqNum != null"> 57 QQ_NUM, 58 </if> 59 <if test="email != null"> 60 EMAIL, 61 </if> 62 <if test="sex != null"> 63 SEX, 64 </if> 65 <if test="party != null"> 66 PARTY, 67 </if> 68 <if test="birthday != null"> 69 BIRTHDAY, 70 </if> 71 <if test="race != null"> 72 RACE, 73 </if> 74 <if test="education != null"> 75 EDUCATION, 76 </if> 77 <if test="speciality != null"> 78 SPECIALITY, 79 </if> 80 <if test="hobby != null"> 81 HOBBY, 82 </if> 83 <if test="remark != null"> 84 REMARK, 85 </if> 86 <if test="createDate != null"> 87 CREATE_DATE, 88 </if> 89 </trim> 90 <trim prefix="values (" suffix=")" suffixOverrides=","> 91 <if test="id != null"> 92 #{id,jdbcType=INTEGER}, 93 </if> 94 <if test="deptId != null"> 95 #{deptId,jdbcType=INTEGER}, 96 </if> 97 <if test="jobId != null"> 98 #{jobId,jdbcType=INTEGER}, 99 </if> 100 <if test="name != null"> 101 #{name,jdbcType=VARCHAR}, 102 </if> 103 <if test="cardId != null"> 104 #{cardId,jdbcType=VARCHAR}, 105 </if> 106 <if test="address != null"> 107 #{address,jdbcType=VARCHAR}, 108 </if> 109 <if test="postCode != null"> 110 #{postCode,jdbcType=VARCHAR}, 111 </if> 112 <if test="tel != null"> 113 #{tel,jdbcType=VARCHAR}, 114 </if> 115 <if test="phone != null"> 116 #{phone,jdbcType=VARCHAR}, 117 </if> 118 <if test="qqNum != null"> 119 #{qqNum,jdbcType=VARCHAR}, 120 </if> 121 <if test="email != null"> 122 #{email,jdbcType=VARCHAR}, 123 </if> 124 <if test="sex != null"> 125 #{sex,jdbcType=VARCHAR}, 126 </if> 127 <if test="party != null"> 128 #{party,jdbcType=VARCHAR}, 129 </if> 130 <if test="birthday != null"> 131 #{birthday,jdbcType=VARCHAR}, 132 </if> 133 <if test="race != null"> 134 #{race,jdbcType=VARCHAR}, 135 </if> 136 <if test="education != null"> 137 #{education,jdbcType=VARCHAR}, 138 </if> 139 <if test="speciality != null"> 140 #{speciality,jdbcType=VARCHAR}, 141 </if> 142 <if test="hobby != null"> 143 #{hobby,jdbcType=VARCHAR}, 144 </if> 145 <if test="remark != null"> 146 #{remark,jdbcType=VARCHAR}, 147 </if> 148 <if test="createDate != null"> 149 #{createDate,jdbcType=VARCHAR}, 150 </if> 151 </trim> 152 </insert> 153 154 155 156 <select id="findAEmploter" parameterType="com.employee.po.EmployeeInf" 157 resultType="com.employee.po.EmployeeInf"> 158 select * from employee_inf 159 <where> 160 <if test="id != null"> 161 and ID = #{id,jdbcType=INTEGER} 162 </if> 163 <if test="deptId != null"> 164 and DEPT_ID = #{deptId,jdbcType=INTEGER} 165 </if> 166 <if test="jobId != null"> 167 and JOB_ID = #{jobId,jdbcType=INTEGER} 168 </if> 169 <if test="name != null"> 170 and NAME = #{name,jdbcType=VARCHAR} 171 </if> 172 <if test="cardId != null"> 173 and CARD_ID = #{cardId,jdbcType=VARCHAR} 174 </if> 175 <if test="address != null"> 176 and ADDRESS = #{address,jdbcType=VARCHAR} 177 </if> 178 <if test="tel != null"> 179 and TEL = #{tel,jdbcType=VARCHAR} 180 </if> 181 <if test="phone != null"> 182 and PHONE = #{phone,jdbcType=VARCHAR} 183 </if> 184 <if test="sex != null"> 185 and SEX = #{sex,jdbcType=INTEGER} 186 </if> 187 </where> 188 </select> 189 190 <delete id="deleteEmployer" parameterType="java.util.List" > 191 delete from employee_inf 192 <where> 193 <foreach collection="list" item="id" separator="," open="and ID in (" close=")"> 194 #{id} 195 </foreach> 196 </where> 197 </delete> 198 199 <update id="updateAEmployer" parameterType="com.employee.po.EmployeeInf"> 200 update employee_inf 201 <set> 202 <if test="deptId != null"> 203 DEPT_ID = #{deptId,jdbcType=INTEGER}, 204 </if> 205 <if test="jobId != null"> 206 JOB_ID = #{jobId,jdbcType=INTEGER}, 207 </if> 208 <if test="name != null"> 209 NAME = #{name,jdbcType=VARCHAR}, 210 </if> 211 <if test="cardId != null"> 212 CARD_ID = #{cardId,jdbcType=VARCHAR}, 213 </if> 214 <if test="address != null"> 215 ADDRESS = #{address,jdbcType=VARCHAR}, 216 </if> 217 <if test="postCode != null"> 218 POST_CODE = #{postCode,jdbcType=VARCHAR}, 219 </if> 220 <if test="tel != null"> 221 TEL = #{tel,jdbcType=VARCHAR}, 222 </if> 223 <if test="phone != null"> 224 PHONE = #{phone,jdbcType=VARCHAR}, 225 </if> 226 <if test="qqNum != null"> 227 QQ_NUM = #{qqNum,jdbcType=VARCHAR}, 228 </if> 229 <if test="email != null"> 230 EMAIL = #{email,jdbcType=VARCHAR}, 231 </if> 232 <if test="sex != null"> 233 SEX = #{sex,jdbcType=VARCHAR}, 234 </if> 235 <if test="party != null"> 236 PARTY = #{party,jdbcType=VARCHAR}, 237 </if> 238 <if test="birthday != null"> 239 BIRTHDAY = #{birthday,jdbcType=TIMESTAMP}, 240 </if> 241 <if test="race != null"> 242 RACE = #{race,jdbcType=VARCHAR}, 243 </if> 244 <if test="education != null"> 245 EDUCATION = #{education,jdbcType=VARCHAR}, 246 </if> 247 <if test="speciality != null"> 248 SPECIALITY = #{speciality,jdbcType=VARCHAR}, 249 </if> 250 <if test="hobby != null"> 251 HOBBY = #{hobby,jdbcType=VARCHAR}, 252 </if> 253 <if test="remark != null"> 254 REMARK = #{remark,jdbcType=VARCHAR}, 255 </if> 256 </set> 257 where ID = #{id,jdbcType=INTEGER} 258 </update> 259 260 <select id="findAllEmployer" resultType="java.util.Map" parameterType="com.DataResult"> 261 SELECT * FROM 262 employee_inf limit #{startLine},#{pageSize} 263 </select> 264 <select id="findAllCount" resultType="Integer"> 265 select count(*) from employee_inf 266 </select> 267 <select id="findAemployee" parameterType="IntegeR" resultMap="BaseResultMap"> 268 select * from employee_inf where ID=#{id} 269 </select> 270 </mapper>