其他分享
首页 > 其他分享> > 客户信息管理查询+客户等级显示+搜索功能+新增

客户信息管理查询+客户等级显示+搜索功能+新增

作者:互联网

客户管理

8 客户信息管理

 @RestController= @Controller  交给spring容器管理
 +@ResponseBody  每一个请求返回json数据

8.1查询客户信息管理数据

1首先逆向工程5张表

CustomerController

 @RestController
 @RequestMapping("customer")
 public class CustomerController {
     @Autowired
     private ICustmoerService custmoerService;
     @GetMapping("")
     public DatagridResult list(int page,int rows){
         return custmoerService.listByPage(page,rows);
    }
 }

ICustmoerService

 public interface ICustmoerService {
     //分页查询客户信息
     DatagridResult listByPage(int page, int rows);
 }

CustomerServiceImpl

 @Service
 public class CustomerServiceImpl implements ICustmoerService {
     @Autowired
     private TCustomerMapper customerMapper;
 ​
     @Override
     public DatagridResult listByPage(int page, int rows) {
         //分页查询
         //1.设置分页条件
         PageHelper.startPage(page,rows);
         //2.查询数据库 list
         List<TCustomer> customerList = customerMapper.selectByExample(null);
         //3.通过list创建PageInfo对象
         PageInfo<TCustomer> pageInfo = new PageInfo<>(customerList);
         //4.根据PageInfo对象中的属性封装DatagridResult对象并返回
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setRows(pageInfo.getList());
         datagridResult.setTotal(pageInfo.getTotal());
         return datagridResult;
    }
 }

8.2显示客户信息管理中的客户等级

逆向一张新华字典表:t_datadic

DataDicController

 @RestController
 @RequestMapping("dataDic")
 public class DataDicController {
     @Autowired
     private IDataDicService dataDicService;
     @PostMapping("selectDic")
     public List<TDatadic> selectDicByName(String name){
         return dataDicService.selectDicByName(name);
    }
 }

IDataDicService

 public interface IDataDicService {
     //查询客户信息管理中的客户等级
     List<TDatadic> selectDicByName(String name);
 }

DataDicServiceImpl

 @Service
 public class DataDicServiceImpl implements IDataDicService {
     @Autowired
     private TDatadicMapper datadicMapper;
 ​
     @Override
     public List<TDatadic> selectDicByName(String name) {
         TDatadicExample example = new TDatadicExample();
         example.createCriteria().andDatadicnameEqualTo(name);
         return datadicMapper.selectByExample(example);
    }
 }

8.3根据搜索框查询,显示数据

CustomerController

 @RestController
 @RequestMapping("customer")
 public class CustomerController {
     @Autowired
     private ICustmoerService custmoerService;
     @GetMapping("")
     public DatagridResult list(int page, int rows, TCustomer customer){
         return custmoerService.listByPage(page,rows,customer);
    }
 }

ICustmoerService

 public interface ICustmoerService {
     //分页查询客户信息,加搜索框查询
     DatagridResult listByPage(int page, int rows, TCustomer customer);
 }

CustomerServiceImpl

 @Service
 public class CustomerServiceImpl implements ICustmoerService {
     @Autowired
     private TCustomerMapper customerMapper;
     @Override
     public DatagridResult listByPage(int page, int rows,TCustomer customer) {
         //分页查询
         //1.设置分页条件
         PageHelper.startPage(page,rows);
         //2.查询数据库 list
         //根据前台输入的条件创建条件对象
         TCustomerExample example = new TCustomerExample();
         TCustomerExample.Criteria criteria = example.createCriteria();
         if (StringUtils.isNotBlank(customer.getKhno())){
             criteria.andKhnoEqualTo(customer.getKhno());
        }
         if (StringUtils.isNotBlank(customer.getName())){
             criteria.andNameLike("%"+customer.getName()+"%");
        }
         List<TCustomer> customerList = customerMapper.selectByExample(example);
         //3.通过list创建PageInfo对象
         PageInfo<TCustomer> pageInfo = new PageInfo<>(customerList);
         //4.根据PageInfo对象中的属性封装DatagridResult对象并返回
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setRows(pageInfo.getList());
         datagridResult.setTotal(pageInfo.getTotal());
         return datagridResult;
    }
 }

8.4新增数据,并拼接客户编号

CustomerController

 @PostMapping("")
 public Map createCus(TCustomer customer){
     //赋值客户编号
     Date date = new Date();
     SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
     String format = sdf.format(date);
     customer.setKhno("KH"+format);
     Map map = new HashMap<>();
     try {
         customerService.createCus(customer);
         map.put("success",true);
    }catch (Exception e){
         e.printStackTrace();
         map.put("success",false);
    }
     return map;
 }

ICustomerService

 public interface ICustomerService {
     //添加客户,保存
     void createCus(TCustomer customer);
 }

CustomerServiceImpl

 @Service
 public class CustomerServiceImpl implements ICustomerService {
     @Autowired
     private TCustomerMapper customerMapper;
     @Override
     public DatagridResult listByPage(int page, int rows,TCustomer customer) {
         //分页查询
         //1.设置分页条件
         PageHelper.startPage(page,rows);
         //2.查询数据库 list
         //根据前台输入的条件创建条件对象
         TCustomerExample example = new TCustomerExample();
         TCustomerExample.Criteria criteria = example.createCriteria();
         if (StringUtils.isNotBlank(customer.getKhno())){
             criteria.andKhnoEqualTo(customer.getKhno());
        }
         if (StringUtils.isNotBlank(customer.getName())){
             criteria.andNameLike("%"+customer.getName()+"%");
        }
         List<TCustomer> customerList = customerMapper.selectByExample(example);
         //3.通过list创建PageInfo对象
         PageInfo<TCustomer> pageInfo = new PageInfo<>(customerList);
         //4.根据PageInfo对象中的属性封装DatagridResult对象并返回
         DatagridResult datagridResult = new DatagridResult();
         datagridResult.setRows(pageInfo.getList());
         datagridResult.setTotal(pageInfo.getTotal());
         return datagridResult;
    }
     //创建
     @Override
     public void createCus(TCustomer customer) {
         customerMapper.insertSelective(customer);
    }
 }
 

标签:customer,int,page,信息管理,查询,客户,DatagridResult,public,datagridResult
来源: https://www.cnblogs.com/wangshikang/p/16371929.html