更新的代码
customerList.java
package org.jsoft.service.impl;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.jsoft.dao.DaoSupport;
import org.jsoft.service.ICustomerService;
import org.jsoft.util.Constants;
import org.springframework.stereotype.Service;
@Service
public class CustomerServiceImpl implements ICustomerService{
@Resource(name = "daoSupport")
private DaoSupport dao;
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> select() {
try {
List<Map<String, Object>> list = dao.findList("customerMapper.selectCAndS", null);
for(Map<String, Object> map : list){
//查询客户的source字段
map.get("source");
map.get("status");
//通过客户的source字段找到 缓存中对应的中文value;
Constants.sourceMap.get(map.get("source"));
Constants.statusMap.get(map.get("status"));
//把对应的中文放回Map中
map.put("sourceName", Constants.sourceMap.get(map.get("source")));
map.put("statusName", Constants.statusMap.get(map.get("status")));
}
return list;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/************************************Day002*************************************************/
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> shaiXuan(Map<String, Object> customer) {
try {
List<Map<String, Object>> list = dao.findList("customerMapper.selectCAndS", customer);
for(Map<String, Object> map : list){
//查询客户的source字段
map.get("source");
map.get("status");
//通过客户的source字段找到 缓存中对应的中文value;
Constants.sourceMap.get(map.get("source"));
Constants.statusMap.get(map.get("status"));
//把对应的中文放回Map中
map.put("sourceName", Constants.sourceMap.get(map.get("source")));
map.put("statusName", Constants.statusMap.get(map.get("status")));
}
return list;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/************************************Day002*************************************************/
@Override
public void delete(String[] arr) {
try {
dao.delete("customerMapper.batchDelete", arr);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
customerCtrl.java
package org.jsoft.ctrls;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jsoft.service.ICustomerService;
import org.jsoft.service.IStatusService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("customerCtrl")
public class CustomerCtrl extends BaseAction{
@Resource
private ICustomerService customerService;
@Resource
private IStatusService statusService;
/**
* 查找所有的客户信息
* */
@RequestMapping("select")
public void select(HttpServletRequest request,HttpServletResponse response){
List<Map<String,Object>> customerList = customerService.select();
//status 公共筛选的内容时动态的,从数据库中查出来的
Map<String,Object> statusMap = new HashMap<String, Object>();
//通过status查询
statusMap.put("columns", "status");
//将查询到的结果放在一个集合中
List<Map<String,Object>> statusList = statusService.select(statusMap);
Map<String,Object> result = new HashMap<String,Object>();
result.put("customerList", customerList);
//把list的值放入一个Map中,用于json传值
result.put("statusList", statusList);
response.setCharacterEncoding("UTF-8");
this.writeJSON(response, result);
}
/************************************Day002*************************************************/
/**
* 通过公共筛选,查找符合条件的客户信息
* */
@RequestMapping("shaiXuan")
public void shaiXuan(HttpServletRequest request,HttpServletResponse response){
String shaiXuan = request.getParameter("shaiXuan");
Map<String,Object> customerMap = new HashMap<String, Object>();
customerMap.put("status", shaiXuan);
List<Map<String,Object>> customerList = customerService.shaiXuan(customerMap);
Map<String,Object> result = new HashMap<String,Object>();
result.put("customerList", customerList);
response.setCharacterEncoding("UTF-8");
this.writeJSON(response, result);
}
/************************************Day002*************************************************/
/**
* 对选中的复选框进行删除
* */
@RequestMapping("delete")
public ModelAndView delete(HttpServletRequest request,HttpServletResponse response){
String delete = request.getParameter("delete");
String[] delId = delete.split(",");
customerService.delete(delId);
ModelAndView mv = new ModelAndView();
mv.setViewName("customerList");
return mv;
}
}
customerList.jsp主要代码
jQuery(document).ready(function($) {
//日期格式化
Date.prototype.format =function(format)
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
};
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
(this.getFullYear()+"").substr(4- RegExp.$1.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length==1? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
return format;
};
ajaxAll();
function ajaxAll(){
$.ajax({
url : "${contextPath }/customerCtrl/select",
type : "post",
dataType : "json",
success : function(msg){
var customerList = msg.customerList;
var customerStr = '';
for(var i = 0; i < customerList.length; i++){
var customer = customerList[i];
customerStr += '<tr>';
customerStr += ' <td>'+ (i + 1)+'</td>';
customerStr += ' <td id="hideId" style="display:none">' + customer.id + '</td>';
customerStr += ' <td>'+ customer.name +'</td>';
customerStr += ' <td>'+ customer.sourceName +'</td>';
customerStr += ' <td><span class="mod_category catcolor_o color_e" title="'+ customer.statusName +'" cid="5">'+ customer.statusName +'</span></td>';
customerStr += ' <td>'+ customer.sname +'</td>';
customerStr += ' <td>'+ new Date(customer.telTime.time).format("yyyy-MM-dd")+'</td>';
customerStr += ' <td>'+ new Date(customer.estimateTime.time).format("yyyy-MM-dd")+'</td>';
customerStr += ' <td>'+ customer.money +'</td>';
customerStr += ' <td>'+ customer.address +'</td>';
customerStr += ' <td>电话:'+ customer.phone +'</td>';
customerStr += ' <td>'+ customer.remark +'</td>';
customerStr += ' <td>'+ customer.file +'</td>';
customerStr += '</tr>';
}
$("#select").html(customerStr);
//*********************************Day002**************************************************************
//像页面中插入公共筛选的状态值
var statusList = msg.statusList;
var statusStr = '<li class="selected" ><b >全部</b></li>';
for(var i = 0; i < statusList.length; i++){
var status = statusList[i];
statusStr += '<li status='+ status.k +'><b >'+ status.v +'</b><cite ><i ></i></cite></li>';
}
$("#status").html(statusStr);
//通过li标签遍历左侧筛选的内容
$("li").click(function(){
if($(this).text() == "全部"){
$("#inp").val("全部");
ajaxAll();
}else{
$("#inp").val($(this).attr("status"));
shaiXuan();
}
})
}//sucess
})//ajax
//*********************************Day002**************************************************************
function shaiXuan(){
$.ajax({
url : "${contextPath }/customerCtrl/shaiXuan",
type : "post",
dataType : "json",
data : $("#shaiXuan").serialize(),
success : function(msg){
var customerList = msg.customerList;
var customerStr = '';
for(var i = 0; i < customerList.length; i++){
var customer = customerList[i];
customerStr += '<tr>';
customerStr += ' <td>'+ (i + 1)+'</td>';
customerStr += ' <td id="hideId" style="display:none">' + customer.id + '</td>';
customerStr += ' <td>'+ customer.name+'</td>';
customerStr += ' <td>'+ customer.sourceName+'</td>';
customerStr += ' <td><span class="mod_category catcolor_o color_e" title="'+ customer.statusName+'" cid="5">'+ customer.statusName+'</span></td>';
customerStr += ' <td>'+ customer.sname+'</td>';
customerStr += ' <td>'+ new Date(customer.telTime.time).format("yyyy-MM-dd")+'</td>';
customerStr += ' <td>'+ new Date(customer.estimateTime.time).format("yyyy-MM-dd")+'</td>';
customerStr += ' <td>'+ customer.money+'</td>';
customerStr += ' <td>'+ customer.address+'</td>';
customerStr += ' <td>电话:'+ customer.phone+'</td>';
customerStr += ' <td>'+ customer.remark+'</td>';
customerStr += ' <td>'+ customer.file+'</td>';
customerStr += '</tr>';
}
$("#select").html(customerStr);
}
})// shaiXuan ajax
//************************************************************************************************
}
}
// 表格操作
$(".tbl").find('tr').each(function(index, el) {
$(this).find('td').first().html(index)
});
$(".tbl").find('th').first().find('input[type=checkbox]').click(function(event) {
if($(this).prop('checked')){
$(".mod_bulkoperation").show()
$(".tbl").find('tr').each(function(index, el) {
var checkinp = "<input type='checkbox' checked='checked' name />"
$(this).find('td').first().html(checkinp)
});
}else {
$(".tbl").find('tr').each(function(index, el) {
var checkinp = "<input type='checkbox' class='check' name />"
$(this).find('td').first().html(checkinp)
});
}
});
$(".cancal_btn").click(function(event) {
$(".mod_bulkoperation").hide()
$(".tbl").find('tr').each(function(index, el) {
$(this).find('td').first().html(index);
});
});
//*********************************Day002**************************************************************
//删除
$(".btn_del").click(function(event) {
var deleteStr = "";
$(".check").each(function(index,element){
if($(this).prop('checked')){
deleteStr += $(this).parent().siblings().eq(0).text()+","
}
});
$("#del").val(deleteStr);
$("#delete").submit();
});
//*****************************************************************************************
});
页面效果
总结
1.完成公共筛选和删除功能
2.对于删除时的已选择/ 条数据,没做修改
3.与搜索有关的内容再整理一下思路,思路不够清晰
4.按条件排序都有什么?跟老师敲定最终排序
5.对于字典值转换成中文,代码重复,不确定是否有更好的办法去解决这个问题