static method with incoming arguments, can be used normally
The function of static is to affirm: This is the static method of the class, when all can be called, can pass in the parameter, also can not pass.
On the code:
1. Classes with static methods:
Public class makeparameters { publicstatic INSURANCESEARCHRQ makebaserqparms ( INSURANCESEARCHRQ RQ) { new channelinfo (); Channel.setfirstchannelno (baseconst.first_channel_no); Channel.setwebsite (baseconst.web_site); Rq.setchannelinfo (channel); Rq.setlanguage (BASECONST.LANGUAG); Rq.settimestamp (baseconst.timestamp); Rq.settransactionid (baseconst.transaction_id); Rq.setversion (baseconst.version); return RQ; }}
View Code
2. Test class:
PackageCom.doit.zz;Importorg.junit.Test;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;Importcom.basemake.zz.MakeParameters;ImportCom.travelsky.logic.insurance.dto.InsuranceSearchRQ;ImportCom.travelsky.logic.insurance.dto.InsuranceSearchRS;ImportCom.travelsky.logic.insurance.dto.MaintainQueryParam;ImportCom.travelsky.logic.shopping.service.IInsuranceSearchService;ImportCom.utils.zz.JsonMapper; Public classinsuretest {applicationcontext ctx=NewClasspathxmlapplicationcontext ("Helloservice.xml"); @Test Public voidTestinsure ()throwsexception{INSURANCESEARCHRQ RQ=NewINSURANCESEARCHRQ (); Maintainqueryparam Maintainqueryparam=NewMaintainqueryparam (); Maintainqueryparam.setproductcode ("7000000"); Rq.setmaintainqueryparam (Maintainqueryparam); Makeparameters.makebaserqparms (RQ); System.out.println (Jsonmapper.tononnulljson (RQ));//1Maintainqueryparam.setproductcode ("12345"); INSURANCESEARCHRQ RQ2=NewINSURANCESEARCHRQ (); Rq2.setmaintainqueryparam (Maintainqueryparam); Makeparameters.makebaserqparms (RQ2); System.out.println (Jsonmapper.tononnulljson (RQ2));//2insurancesearchrs rs=Newinsurancesearchrs (); Iinsurancesearchservice Insservice= (Iinsurancesearchservice) ctx.getbean ("Iinsurancesearchservice"); RS=insservice.getinsurancesearchrs (RQ); String Rsjson=Jsonmapper.tononnulljson (RS); System.out.println (Rsjson); } }View Code
3. Results
{"Channelinfo": {"Firstchannelno": "", "" WebSite ":" ZH_CN "}," TimeStamp ":" 20150108161025 "," Version ":" 0.01 "," TransactionID ":" 20150108161025 "," language ":" zh "," Instravelerinfos ": []," Maintainqueryparam ": {" ProductCode ":" 7000000 "}}
{"Channelinfo": {"Firstchannelno": "", "" WebSite ":" ZH_CN "}," TimeStamp ":" 20150108161025 "," Version ":" 0.01 "," TransactionID ":" 20150108161025 "," language ":" zh "," Instravelerinfos ": []," Maintainqueryparam ": {" ProductCode ":" 12345 "}}
Static method results are called at 1 and 2 out of separate print
You can see: Two calls to static methods: The arguments are different, and the results are different.
Java static method using notes