java static 方法使用笔记

有入参的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));// maintainQueryParam.setProductCode("12345");
InsuranceSearchRQ rq2=new InsuranceSearchRQ();
rq2.setMaintainQueryParam(maintainQueryParam);
MakeParameters.makeBaseRqParms(rq2);
System.out.println(JsonMapper.toNonNullJson(rq2));// 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出分别打印调用静态方法结果

可以看到:两次调用静态方法:入参不一样,结果也是不一样的。

上一篇:vc 基于对话框多线程编程实例——线程之间的通信


下一篇:C++ 多线程编程实例【2个线程模拟卖火车票的小程序】