1 //1.controlle层 2 @Controller 3 @RequestMapping("customer") 4 public class CustomerController { 5 @Autowired 6 private BaseDictService dictService; 7 @Autowired 8 private CustomerService customerService; 9 10 @Value("${CUSTOMER_FROM_TYPE}") 11 private String CUSTOMER_FROM_TYPE; 12 //客户行业编码 13 @Value("${CUSTOMER_INDUSTRY_TYPE}") 14 private String CUSTOMER_INDUSTRY_TYPE; 15 //客户级别编码 16 @Value("${CUSTOMER_LEVEL_TYPE}") 17 private String CUSTOMER_LEVEL_TYPE; 18 19 @RequestMapping("list") 20 public String list(Model model,QueryVo vo) { 21 22 // 来源查询 23 List<BaseDict> fromType = dictService.getBaseDictByCode(CUSTOMER_FROM_TYPE); 24 // 行业查询 25 List<BaseDict> industryType = dictService.getBaseDictByCode(CUSTOMER_INDUSTRY_TYPE); 26 // 来源查询 27 List<BaseDict> levelType = dictService.getBaseDictByCode(CUSTOMER_LEVEL_TYPE); 28 29 30 //分页查询用户列表 31 Page<Customer> page = customerService.getCustomerByQueryVo(vo); 32 33 //设置数据模型返回 34 model.addAttribute("fromType", fromType); 35 model.addAttribute("industryType", industryType); 36 model.addAttribute("levelType", levelType); 37 38 //设置分页数据返回 39 model.addAttribute("page", page); 40 41 //查询条件回显 42 model.addAttribute("vo", vo); 43 44 return "customer"; 45 } 46 }
//编辑
@RequestMapping("edit")
@ResponseBody
public Customer edit(Integer id){
Customer customer = customerService.getCustomerById(id);
return customer;
}
jsp页面展示
<!-- 客户编辑对话框 --> <div class="modal fade" id="customerEditDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title" id="myModalLabel">修改客户信息</h4> </div> <div class="modal-body"> <form class="form-horizontal" id="edit_customer_form"> <input type="hidden" id="edit_cust_id" name="cust_id"/> <div class="form-group"> <label for="edit_customerName" class="col-sm-2 control-label">客户名称</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_customerName" placeholder="客户名称" name="cust_name"> </div> </div> <div class="form-group"> <label for="edit_customerFrom" style="float:left;padding:7px 15px 0 27px;">客户来源</label> <div class="col-sm-10"> <select class="form-control" id="edit_customerFrom" placeholder="客户来源" name="cust_source"> <option value="">--请选择--</option> <c:forEach items="${fromType}" var="item"> <option value="${item.dict_id}"<c:if test="${item.dict_id == custSource}"> selected</c:if>>${item.dict_item_name }</option> </c:forEach> </select> </div> </div> <div class="form-group"> <label for="edit_custIndustry" style="float:left;padding:7px 15px 0 27px;">所属行业</label> <div class="col-sm-10"> <select class="form-control" id="edit_custIndustry" name="cust_industry"> <option value="">--请选择--</option> <c:forEach items="${industryType}" var="item"> <option value="${item.dict_id}"<c:if test="${item.dict_id == custIndustry}"> selected</c:if>>${item.dict_item_name }</option> </c:forEach> </select> </div> </div> <div class="form-group"> <label for="edit_custLevel" style="float:left;padding:7px 15px 0 27px;">客户级别</label> <div class="col-sm-10"> <select class="form-control" id="edit_custLevel" name="cust_level"> <option value="">--请选择--</option> <c:forEach items="${levelType}" var="item"> <option value="${item.dict_id}"<c:if test="${item.dict_id == custLevel}"> selected</c:if>>${item.dict_item_name }</option> </c:forEach> </select> </div> </div> <div class="form-group"> <label for="edit_linkMan" class="col-sm-2 control-label">联系人</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_linkMan" placeholder="联系人" name="cust_linkman"> </div> </div> <div class="form-group"> <label for="edit_phone" class="col-sm-2 control-label">固定电话</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_phone" placeholder="固定电话" name="cust_phone"> </div> </div> <div class="form-group"> <label for="edit_mobile" class="col-sm-2 control-label">移动电话</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_mobile" placeholder="移动电话" name="cust_mobile"> </div> </div> <div class="form-group"> <label for="edit_zipcode" class="col-sm-2 control-label">邮政编码</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_zipcode" placeholder="邮政编码" name="cust_zipcode"> </div> </div> <div class="form-group"> <label for="edit_address" class="col-sm-2 control-label">联系地址</label> <div class="col-sm-10"> <input type="text" class="form-control" id="edit_address" placeholder="联系地址" name="cust_address"> </div> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary" onclick="updateCustomer()">保存修改</button> </div> </div> </div> </div> <!-- /#wrapper --> <!-- jQuery --> <script src="<%=basePath%>js/jquery.min.js"></script> <!-- Bootstrap Core JavaScript --> <script src="<%=basePath%>js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript --> <script src="<%=basePath%>js/metisMenu.min.js"></script> <!-- DataTables JavaScript --> <script src="<%=basePath%>js/jquery.dataTables.min.js"></script> <script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script> <!-- Custom Theme JavaScript --> <script src="<%=basePath%>js/sb-admin-2.js"></script> <script type="text/javascript"> function editCustomer(id) { $.ajax({ type:"get", url:"<%=basePath%>customer/edit.action", data:{"id":id}, success:function(data) { $("#edit_cust_id").val(data.cust_id); $("#edit_customerName").val(data.cust_name); $("#edit_customerFrom").val(data.cust_source) $("#edit_custIndustry").val(data.cust_industry) $("#edit_custLevel").val(data.cust_level) $("#edit_linkMan").val(data.cust_linkman); $("#edit_phone").val(data.cust_phone); $("#edit_mobile").val(data.cust_mobile); $("#edit_zipcode").val(data.cust_zipcode); $("#edit_address").val(data.cust_address); } }); } function updateCustomer() { $.post("<%=basePath%>customer/update.action",$("#edit_customer_form").serialize(),function(data){ if(data == "0"){ alert("客户信息更新成功!"); }else{ alert("客户信息更新失败!"); } window.location.reload(); }); } function deleteCustomer(id) { if(confirm('确实要删除该客户吗?')) { $.post("<%=basePath%>customer/delete.action",{"id":id},function(data){ if(data == "0"){ alert("客户信息删除成功!"); }else{ alert("客户信息删除失败!"); } window.location.reload(); }); } } </script>