有入参的static方法,可以正常使用
static的作用是申明:这是类的静态方法,什么时候都可以调用,可以传入入参,也可以不传。
上代码:
1.带静态方法的类:
public class MakeParameters { public static InsuranceSearchRQ makeBaseRqParms(InsuranceSearchRQ rq){ ChannelInfo channel = 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; } }
2.测试类:
package com.doit.zz; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.basemake.zz.MakeParameters; import com.travelsky.logic.insurance.dto.InsuranceSearchRQ; import com.travelsky.logic.insurance.dto.InsuranceSearchRS; import com.travelsky.logic.insurance.dto.MaintainQueryParam; import com.travelsky.logic.shopping.service.IInsuranceSearchService; import com.utils.zz.JsonMapper; public class InsureTest { ApplicationContext ctx=new ClassPathXmlApplicationContext("helloservice.xml"); @Test public void testInsure() throws Exception{ InsuranceSearchRQ rq=new InsuranceSearchRQ(); MaintainQueryParam maintainQueryParam=new MaintainQueryParam(); maintainQueryParam.setProductCode("7000000"); rq.setMaintainQueryParam(maintainQueryParam); MakeParameters.makeBaseRqParms(rq); System.out.println(JsonMapper.toNonNullJson(rq));//1 maintainQueryParam.setProductCode("12345"); InsuranceSearchRQ rq2=new InsuranceSearchRQ(); rq2.setMaintainQueryParam(maintainQueryParam); MakeParameters.makeBaseRqParms(rq2); System.out.println(JsonMapper.toNonNullJson(rq2));//2 InsuranceSearchRS rs=new InsuranceSearchRS(); IInsuranceSearchService insService=(IInsuranceSearchService)ctx.getBean("iInsuranceSearchService"); rs=insService.getInsuranceSearchRS(rq); String rsJson = JsonMapper.toNonNullJson(rs); System.out.println(rsJson); } }
3.结果
{"channelInfo":{"firstChannelNo":"71","webSite":"zh_CN"},"timeStamp":"20150108161025","version":"0.01","transactionId":"20150108161025","language":"zh","insTravelerInfos":[],"maintainQueryParam":{"productCode":"7000000"}}
{"channelInfo":{"firstChannelNo":"71","webSite":"zh_CN"},"timeStamp":"20150108161025","version":"0.01","transactionId":"20150108161025","language":"zh","insTravelerInfos":[],"maintainQueryParam":{"productCode":"12345"}}
在1处和2出分别打印调用静态方法结果
可以看到:两次调用静态方法:入参不一样,结果也是不一样的。
时间: 2024-10-24 05:58:09