首页>代码>spring+spring mvc+mybatis开发的java客户关系管理系统,前端采用easyui编写>/ssm-crm-new - 副本/src/com/crm/controller/CustomerController.java
/**
 * 
 */
package com.crm.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.Customer;
import com.crm.model.easyui.DataGrid;
import com.crm.model.easyui.Json;
import com.crm.model.easyui.PageHelper;
import com.crm.service.CustomerService;

/**
 * @author zh
 */
@Controller
public class CustomerController {
	
	private final Logger log = LoggerFactory.getLogger(CustomerController.class);
	
	@Resource
	private CustomerService customerService;
	
	/**
	 * 跳转到客户表格页面
	 * @return
	 */
	@RequestMapping(value = "/customer/list",method = RequestMethod.GET)
    public String customerList(Model model) {
        return "crm/customer_list";
    }
	
	/**
	 * 表格
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/customer/datagrid", method = RequestMethod.POST)
	public DataGrid datagrid(PageHelper page,Customer customer) {
		DataGrid dg = new DataGrid();
		dg.setTotal(customerService.getDatagridTotal(customer));
		List<Customer> list = customerService.datagridCustomer(page);
		dg.setRows(list);
		return dg;
	}
	
	/**
	 * 新增
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/customer/add",method = RequestMethod.POST)
    public Json add(Customer customer) {
		Json j = new Json();
		
		try {
			customerService.addCustomer(customer);
            j.setSuccess(true);
            j.setMsg("用户新增成功!");
            j.setObj(customer);
        } catch (Exception e) {
            j.setMsg(e.getMessage());
        }
        return j;
    }
	
	/**
     * 修改
     * 
     * @return
     */
	@ResponseBody
    @RequestMapping(value = "/customer/edit",method = RequestMethod.POST)
    public Json editUser(Customer customer) {
        Json j = new Json();
        log.debug("穿过来的用户ID为:"+customer.getId());
        try {
        	customerService.editCustomer(customer);
            j.setSuccess(true);
            j.setMsg("编辑成功!");
            j.setObj(customer);
        } catch (Exception e) {
            j.setMsg(e.getMessage());
        }
        return j;
    }
	
	/**
	 * 删除某个
	 * @param out
	 */
	@ResponseBody
	@RequestMapping(value = "/customer/delete",method = RequestMethod.POST)
	public Json delete(Customer customer) {
		Json j = new Json();
        log.debug("穿过来的用户ID为:"+customer.getId());
        try {
        	customerService.deleteCustomer(customer.getId());
			j.setSuccess(true);
	        j.setMsg("删除成功!");
        } catch (Exception e) {
            j.setMsg(e.getMessage());
        }
        return j;
	}
}
最近下载更多
sunlea  LV20 2024年5月23日
爱丽淇  LV5 2024年3月18日
杨豫川  LV12 2023年5月31日
qq1061521319  LV4 2022年9月15日
wangyang520  LV6 2022年5月2日
crofsun  LV8 2022年3月28日
543666826  LV34 2021年11月19日
cyrus6693  LV2 2021年10月25日
lironggang  LV38 2021年8月31日
小安同学  LV7 2021年6月20日
最近浏览更多
Solowen 4月16日
暂无贡献等级
cq1458824624 1月14日
暂无贡献等级
张春青  LV6 2024年11月14日
123456cjj  LV1 2024年6月2日
sunlea  LV20 2024年5月22日
李俊雄  LV3 2024年4月30日
FFF112233  LV8 2024年3月27日
爱丽淇  LV5 2024年3月18日
qq3577025766  LV6 2024年3月8日
阿凡达  LV9 2024年1月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友