/** * 更新客户资料信息 * * @param request * @param response * @return * @throws Exception */ public ModelAndView updateClient(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("更新客户资料"); // 获取表单数据 String clientId = request.getParameter("id"); String name = request.getParameter("name"); String sex = request.getParameter("sex"); sex = "1".equals(sex) ? "女" : "男"; String post = request.getParameter("post"); String brithday = request.getParameter("brithday"); String tel = request.getParameter("tel"); String address = request.getParameter("address"); Client client = clientAdminService.findClientById(Integer.parseInt(clientId)); System.out.println("client : " + client); Map<String, Object> errors = new HashMap<String, Object>(); Map<String, Object> models = new HashMap<String, Object>(); // 修改资料 try { // 校验表单数据 if (isEmptyParam(name)) { System.out.println("请输入姓名??"); errors.put("name", "请输入姓名"); } if (errors.size() > 0) { models.put("client", client); models.put("errors", errors); return new ModelAndView(getClientInfoUpdateView(), models); } client.setName(name); client.setSex(sex); client.setPost(post); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date bdDate = brithday == null || brithday.trim().isEmpty() ? null : sdf.parse(brithday); client.setBrithday(bdDate); client.setTel(tel); client.setAddress(address); clientAdminService.updateInfo(client); models.put("message", "修改成功"); } catch (Exception e) { errors.put("message", "修改失败"); e.printStackTrace(); } models.put("errors", errors); models.put("client", client); System.out.println(models.size() + "," + models); return new ModelAndView(getClientInfoUpdateView(), models); }
/** * 客户资料详情 * * @param request * @param response * @return * @throws Exception */ public ModelAndView clientInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("clientInfo"); String clientId = request.getParameter("id"); String action = request.getParameter("action"); int cid = clientId == null || clientId.trim().isEmpty() || !clientId.matches("\\d+") ? -1 : Integer.parseInt(clientId); // 查找客户资料 Client client = clientAdminService.findClientById(cid); String view = null; if ("edit".equals(action)) { // 返回编辑页面 view = getClientInfoUpdateView(); } else { // 返回详情页面 view = getClientInfoDetailView(); } return new ModelAndView(view, "client", client); }