有两个类结构差不多,都在Order类里面用到,而且方法里面逻辑也差不多,怎么优化因为Customer和Client不同类型,所以写了两个方法,只是传的参数不一样自定义泛型可以实现么,怎么写比较好,或者其它有什么方式谢谢publicclassCustomer{privateStringlocation;privateBooleanisDone;//getsettoString...}publicclassClient{privateStringlocation;privateBooleanisDone;//getsettoString...}publicclassOrder{publicvoidexecute_customer(Customercustomer){if(customer.getDone()){customer.setLocation("hongkong");}System.out.println("result:"+customer);}publicvoidexecute_client(Clientclient){if(client.getDone()){client.setLocation("hongkong");}System.out.println("result:"+client);}}=============================情况二=====================================publicListretrieveEntityRecords(RequestParamrequest){Listids=request.getId();Stringlocation=request.getLocation();booleanidsCk=CollectionUtils.isNotEmpty(ids)&&ids.size()>0;booleanlocationCk=!StringUtils.isEmpty(location);Listresult;try{if(idsCk){if(locationCk){//use[idslocation]querydbresult=customerRepository.findxxx(ids,location);}else{//use[ids]querydbresult=customerRepository.findxxx(ids);}}else{if(locationCk){//use[location]querydbresult=customerRepository.findxxx(location);}else{//queryallrecordindbresult=customerRepository.findxxx();}}}catch(Exceptione){thrownewSystemException();}returnresult;}publicListretrieveEntityRecords(RequestParamrequest){Listids=request.getId();Stringlocation=request.getLocation();booleanidsCk=CollectionUtils.isNotEmpty(ids)&&ids.size()>0;booleanlocationCk=!StringUtils.isEmpty(location);Listresult;try{if(idsCk){if(locationCk){//use[idslocation]querydbresult=clientRepository.findxxx(ids,location);}else{//use[ids]querydbresult=clientRepository.findxxx(ids);}}else{if(locationCk){//use[location]querydbresult=clientRepository.findxxx(location);}else{//queryallrecordindbresult=clientRepository.findxxx();}}}catch(Exceptione){thrownewSystemException();}returnresult;}
添加回答
举报
0/150
提交
取消