xz学习记录-后台部分

项目描述

一个进行校园招聘的平台。在校生的信息导入进平台中,学生要进行注册激活。企业可以在平台发布工作信息,可以查看学生并对其进行面试邀请。学生则可以在平台进行查找工作,投递自己的简历。


项目整体采用了springMVC模式。与数据库的交互使用了myBatis。还进行了微信公众号的开发。在微信上的操作和PC端一致,删减了部分功能。

前端以及后台整体页面都用了bootstrap框架。直接套用已成型的框架,进行页面的修改。

后台的表格来源于datatables。界面中先设置好表格的形式,比如


		<table class="table table-striped table-bordered" id="adminuser">
							<thead>
								<tr>
									<th></th>

									<th>账户</th>
									<th>密码</th>
									<th>负责人姓名</th>
									<th>邮箱</th>
									<th>联系电话</th>
									<th>绑定微信</th>
									<th>所属组织名称</th>
									<th>所属组织</th>
									<th>操作</th>
								</tr>
							</thead>
							<tfoot>
								<tr>
									<th></th>
									<th>账户</th>
									<th>密码</th>
									<th>负责人姓名</th>
									<th>邮箱</th>
									<th>联系电话</th>
									<th>绑定微信</th>
									<th>所属组织名称</th>
									<th>所属组织</th>
									<th></th>
								</tr>
							</tfoot>


						</table>

然后在js中去后台获取数据,再将数据中的值填入表格对应的字段,需要注意的是,所有的字段都要与数据库中的字段对应。然后可以进行相应的事件的操作,也同样在DataTable()中去设置。还可以在当中去拼接表格部分。

adminuser = $("#adminuser").DataTable(
		{

			"pageLength":10,
			"ajax": {
				"url": "../adminuser/getAll",
				"type": "POST"
			},
			'paging': true,
			"destory": true,
			"retrieve": true,
			"filter":true,
			"scrollX": true,
			"sort": false,
			"processing": true,
			"serverSide":true,
			"serverMethod":"post",
			"language": {
	            "url": "../../res/admin/js/Chinese.json"
	        },
			"columns": [
			            {
			            	"data": "id",
			            	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            		$(nTd).html("<input class='checkboxlist' type='checkbox' name='checkList' value='" + sData + "'>");
			            		
			            	}
			            },
			            {"data": "username"},
			            {"data": "password"},
			            {"data": "name"},
			            {"data": "email"},
			            {"data": "phone"},
			            {"data": "openid"},
			            {"data": "orgname"},
			            {"data": "orgid"},
			
			            {
			            	"data": "id",
			            	"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
			            		$(nTd).html("<a href='editor/"+oData.id+"'>编辑</a>")
			            		.append("<a href='javascript:void(0);' οnclick='_deleteadminuserFun(" + oData.id + ")'>删除</a>");
			            		       }
			            }],
	        "fnCreatedRow": function (nRow, aData, iDataIndex) {
	        	//add selected class
	        	$(nRow).click(function () {
	        		if ($(this).hasClass('row_selected')) {
	        			$(this).removeClass('row_selected');
	        		} else {
	        			adminuser.$('tr.row_selected').removeClass('row_selected');
	        			$(this).addClass('row_selected');
	        		}
	        	});
	        },
	        "sDom":"<'row'<'col-xs-2' l><'#mytool.col-xs-4'><'col-xs-6'f>r>" +
	        "t" +
	        "<'row'<'col-xs-6'i><'col-xs-6'p>>",
	        "fnInitComplete": function () {
	        	$("#mytool").append('              <a href="add" class="btn btn-default btn-sm" >添加</a>');
	        	
	        }
	 

});
在后台的数据中用到了树的概念,采用了ztree的插件。

对于后台的操作,主要集中在增删改查,权限分配以及用户角色管理。本质上是对于数据库的基本操作。

关于数据库的部分采用了mybatis.。在mybatis.xml中配置实体,在每个xml文件中对应实体。写好接口对应xml文件中的方法。在service层的实现类中去调用方法,进行逻辑的处理。

关于上传excel文件的处理。与普通文件的上传没有很大的区别,只是需要将对应的列写进数据库中的字段。需要制定好excel的格式。采用了ajaxFileUpload进行上传。

表单部分

		<form name="excelImportForm" action="" method="get"
						enctype="multipart/form-data" id="questionTypesManage">
						<input type="hidden" name="ids" id="ids">
					
							<div class="row gap">
								<label class="col-sm-7 control-label"> <input style="width:550px;margin-left: 10px;"
									class="btn btn-default" id="uploadExcel" type="file"
									name="filename" accept="xls" />

								</label>
							</div>
						
					</form>

使用ajax进行传输,先判断是否为excel文件

var filename=$("#uploadExcel").val();
			if(filename==null||filename==""){
			alert("选择一个Excel文件!");
			}else{
		    var ext=filename.slice(filename.lastIndexOf(".")+1).toLowerCase();  
		    if ("xls" != ext) {  
		        alert("只能上传Excle文件");  
		        return false;  
		    }  
$.ajaxFileUpload({
				url : '../students/addExcel',
				type : 'get',
				secureuri : false, //一般设置为false
				fileElementId : 'uploadExcel', // 上传文件的id、name属性名
				dataType : 'json', //返回值类型,一般设置为json、application/json
				//elementIds : elementIds, //传递参数到服务器
				success : function(result, status) {
					$("#progressDiv").hide();				
					var html="";
					$.each(result,function(i,data1)<pre name="code" class="java">
{if(data1.success!=null){html=html+"<span>其余数据导入结果:合法数据导入成功!</span><br/>";}if(data1.row!=null){html=html+"<span>已存在数据返回:"+data1.row+"</span>,请在表中删除该行数据<br/>";}if(data1.error!=null){html=html+"<span>出错数据返回:"+data1.error+"</span>,请在表中检查该行数据<br/>";}$("#result").html(html);});},});return false;}

 

输出的结果来源于后台的处理

/**
 * 判断输入 的格式
 * @param hssfCell
 * @return
 */
	@SuppressWarnings("static-access")
	private String getValue(HSSFCell hssfCell) {
		if (hssfCell != null) {
			if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
				// 返回布尔类型的值
				return String.valueOf(hssfCell.getBooleanCellValue());
			}
			if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
				// 返回数值类型的值
				return String.valueOf(hssfCell.getNumericCellValue());
			}
			if (hssfCell.getCellType() == hssfCell.CELL_TYPE_STRING) {
				// 返回字符串类型的值
				return String.valueOf(hssfCell.getStringCellValue());
			}
			if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BLANK) {
				return "error";
			}
		}
		return null;
	}
<span style="white-space:pre">	</span>public List<Map<String, String>> toList(InputStream is) throws IOException, ParseException {
<span style="white-space:pre">		</span>boolean b;
<span style="white-space:pre">		</span>List<String> results = new ArrayList<String>();
<span style="white-space:pre">		</span>String result = "";
<span style="white-space:pre">		</span>HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
<span style="white-space:pre">		</span>List<Students> students = new ArrayList<Students>();
<span style="white-space:pre">		</span>List<Resumes> resumes = new ArrayList<Resumes>();
<span style="white-space:pre">		</span>// Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">		</span>List<Map<String, String>> res = returnResult();
<span style="white-space:pre">		</span>Students student;
<span style="white-space:pre">		</span>// 循环工作表Sheet
<span style="white-space:pre">		</span>for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
<span style="white-space:pre">			</span>HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
<span style="white-space:pre">			</span>if (hssfSheet == null) {
<span style="white-space:pre">				</span>continue;
<span style="white-space:pre">			</span>}
<span style="white-space:pre">			</span>// 循环行Row
<span style="white-space:pre">			</span>for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
<span style="white-space:pre">				</span>student = new Students();
<span style="white-space:pre">				</span>Resumes r = new Resumes();
<span style="white-space:pre">				</span>HSSFRow hssfRow = hssfSheet.getRow(rowNum);
<span style="white-space:pre">				</span>HSSFCell hc = hssfRow.getCell(5);
<span style="white-space:pre">				</span>String hcv = getValue(hc);


<span style="white-space:pre">			</span>Students s = studentsMapper.getStudentByPhone(hcv);
<span style="white-space:pre">				</span>if (s == null) {
<span style="white-space:pre">					</span>for (int i = 0; i < hssfRow.getLastCellNum(); i++) {
<span style="white-space:pre">						</span>HSSFCell brandIdHSSFCell = hssfRow.getCell((short) i);
<span style="white-space:pre">						</span>System.out.println(brandIdHSSFCell);


<span style="white-space:pre">						</span>if (brandIdHSSFCell == null) {
<span style="white-space:pre">							</span>student.setError("第" + (rowNum + 1) + "行,第" + (i + 1) + "列出错");
<span style="white-space:pre">							</span>result = "第" + (rowNum + 1) + "行,第" + (i + 1) + "列出错";
<span style="white-space:pre">							</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">							</span>map.put("error", result);
<span style="white-space:pre">							</span>res.add(map);
<span style="white-space:pre">							</span>break;
<span style="white-space:pre">						</span>} else {
<span style="white-space:pre">							</span>if (i == 0) {
<span style="white-space:pre">								</span>student.setName(getValue(brandIdHSSFCell));
<span style="white-space:pre">								</span>r.setName(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 1) {
<span style="white-space:pre">								</span>student.setSno(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 2) {
<span style="white-space:pre">								</span>student.setSex(getValue(brandIdHSSFCell));
<span style="white-space:pre">								</span>r.setSex(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 3) {
<span style="white-space:pre">							</span>Date d =<span style="white-space:pre">	</span>getDate(brandIdHSSFCell);
<span style="white-space:pre">							</span>System.out.println(d+"1111");
<span style="white-space:pre">								</span>if (getDate(brandIdHSSFCell) != null) {
<span style="white-space:pre">									</span>student.setBirthday(getDate(brandIdHSSFCell));
<span style="white-space:pre">									</span>r.setBirthday(getDate(brandIdHSSFCell));
<span style="white-space:pre">								</span>} else {
<span style="white-space:pre">									</span>result = "第" + (rowNum ) + "行,第" + (i + 1) + "列出错";
<span style="white-space:pre">									</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">									</span>map.put("row", result);
<span style="white-space:pre">									</span>res.add(map);
<span style="white-space:pre">								</span>}


<span style="white-space:pre">							</span>} else if (i == 4) {
<span style="white-space:pre">								</span>if (getDate(brandIdHSSFCell) != null) {
<span style="white-space:pre">									</span>Date d = getDate(brandIdHSSFCell);
<span style="white-space:pre">									</span>student.setIntime(d);
<span style="white-space:pre">									</span>if (d != null) {
<span style="white-space:pre">										</span>r.setGrade((d.getYear() + 1900) + "");
<span style="white-space:pre">									</span>}
<span style="white-space:pre">								</span>} else {
<span style="white-space:pre">									</span>result = "第" + (rowNum ) + "行,第" + (i + 1) + "列出错";
<span style="white-space:pre">									</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">									</span>map.put("row", result);
<span style="white-space:pre">									</span>res.add(map);
<span style="white-space:pre">								</span>}
<span style="white-space:pre">							</span>} else if (i == 5) {
<span style="white-space:pre">								</span>student.setTelephone(getValue(brandIdHSSFCell));
<span style="white-space:pre">								</span>r.setTelephone(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 6) {
<span style="white-space:pre">								</span>student.setEmail(getValue(brandIdHSSFCell));
<span style="white-space:pre">								</span>r.setEmail(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 7) {
<span style="white-space:pre">								</span>student.setCountry(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 8) {
<span style="white-space:pre">								</span>student.setNativeplace(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 9) {
<span style="white-space:pre">								</span>student.setNational(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 10) {
<span style="white-space:pre">								</span>student.setPoliticalstatus(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 11) {
<span style="white-space:pre">								</span>student.setClassname(getValue(brandIdHSSFCell));
<span style="white-space:pre">							</span>} else if (i == 12) {
<span style="white-space:pre">								</span>String classcode = getValue(brandIdHSSFCell);
<span style="white-space:pre">								</span>student.setClasscode(classcode);
<span style="white-space:pre">								</span>// 去班级里面查classcode如果不存在不能导入。
<span style="white-space:pre">								</span>int count = 0;
<span style="white-space:pre">								</span>try {
<span style="white-space:pre">									</span>count = classService.validateClasscodeisExit(classcode);
<span style="white-space:pre">									</span>if (count == 0) {
<span style="white-space:pre">										</span>student.setError("第" + (rowNum ) + "行,第" + (i + 1) + "列出错没有此班级");
<span style="white-space:pre">										</span>String rr = "第" + (rowNum ) + "行,第" + (i + 1) + "列出错没有此班级,请先添加此班级";
<span style="white-space:pre">										</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">										</span>map.put("row", rr);
<span style="white-space:pre">										</span>res.add(map);
<span style="white-space:pre">									</span>} else {
<span style="white-space:pre">										</span>Classes c = classService.getClassByClasscode(classcode);
<span style="white-space:pre">										</span>student.setClassesid(c.getId());绑定classid
<span style="white-space:pre">										</span>Organ organ = organService.getOrgSchoolMajorById(c.getOrganid());
<span style="white-space:pre">										</span>r.setSchool(organ.getSchoolName());
<span style="white-space:pre">										</span>r.setMajor(organ.getProfessionalName());
<span style="white-space:pre">										</span>student.setClassname(c.getName());
<span style="white-space:pre">									</span>}
<span style="white-space:pre">								</span>} catch (Exception e) {
<span style="white-space:pre">									</span>e.printStackTrace();
<span style="white-space:pre">								</span>}


<span style="white-space:pre">							</span>}
<span style="white-space:pre">						</span>}
<span style="white-space:pre">					</span>}


<span style="white-space:pre">					</span>if (student.getError() == null || student.getError().equals("")) {
<span style="white-space:pre">						</span>students.add(student);
<span style="white-space:pre">						</span>resumes.add(r);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>} else {
<span style="white-space:pre">					</span>result = "第" + (rowNum ) + "行已存在";
<span style="white-space:pre">					</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">					</span>map.put("row", result);
<span style="white-space:pre">					</span>res.add(map);
<span style="white-space:pre">				</span>}


<span style="white-space:pre">			</span>}
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>for (Students s : students) {
<span style="white-space:pre">			</span>if(s!=null){
<span style="white-space:pre">			</span>studentsMapper.save(s);
<span style="white-space:pre">				</span>EnterpriseUser user = euService.getEnterpriseUserByUsername(s.getTelephone());
<span style="white-space:pre">				</span>if (user!=null&&user.getEpidorstudentid() == null) {
<span style="white-space:pre">					</span>euService.updateEpIdORSId(s.getTelephone(), s.getId());
<span style="white-space:pre">				</span>}
<span style="white-space:pre">				</span>s.setId(s.getId());
<span style="white-space:pre">			</span>}


<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>for (int j = 0; j < resumes.size(); j++) {
<span style="white-space:pre">			</span>Resumes r = resumes.get(j);
<span style="white-space:pre">			</span>r.setStudentid(students.get(j).getId());
<span style="white-space:pre">			</span>r.setUpdatetime(MyTimeUtils.getNowFormatDate("yyyy-MM-dd  HH:mm:ss"));
<span style="white-space:pre">			</span>resuumesMapper.saveBaseInforsResumes(r);
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>Map<String, String> map = new HashMap<String, String>();
<span style="white-space:pre">		</span>map.put("success", "success");
<span style="white-space:pre">		</span>res.add(map);


<span style="white-space:pre">		</span>return res;


<span style="white-space:pre">	</span>}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值