가변형 List 매개변수 사용, 동적 반환 함수

BaseClass.java

protected <E> void setResponse(ModelMap model, List<E> ... resListArray) {

    Box resDatas = new Box();
    int listIndex = 0;
    for (List E : resListArray) {
        resDatas.put(RepItemName.RES_LIST_PREFIX + String.format("%03d", ++listIndex), E);
    }

    //...
}

callClass.java

public void getExam00002(ModelMap model) {

    Exam00002ReqVO reqParam = getRequestVO(Exam00002ReqVO.class);

    List<Exam00002Res1VO> resList1 = mtDao.selectList("mt.exam.em.EmNee.selectNewExamStudentChk1", reqParam);

    List<Exam00002Res2VO> resList2 = mtDao.selectList("mt.exam.em.EmNee.selectNewExamStudentChk2", reqParam);

    //여기처럼
    List[] resList = {resList1, resList2};      

    setResponse(model, resList);
}
또는 아래처럼 Arrays.asList를 사용해도 됨.
BassClass.java
protected <E> void setResponse(ModelMap model, List<E> resListArray) {

    Box resDatas = new Box();
    int listIndex = 0;
    for (E list: resListArray) {
        resDatas.put(RepItemName.RES_LIST_PREFIX + String.format("%03d", ++listIndex), list);
    }

    Box resParamBox = new Box();
    resParamBox.put(EnpApiConst.SpParamName.ERR_CD, EnpApiConst.SpValue.SUCCESS_CD);
    resParamBox.put(EnpApiConst.SpParamName.ERR_MSG, EnpApiConst.SpValue.SUCCESS_MSG);

    //...
}
callClass.java
import java.util.Arrays;

public void getExam00002(ModelMap model) {
    Exam00002ReqVO reqParam = getRequestVO(Exam00002ReqVO.class);

    List<Exam00002Res1VO> resList1 = mtDao.selectList("mt.exam.em.EmNee.selectNewExamStudentChk1", reqParam);

    List<Exam00002Res2VO> resList2 = mtDao.selectList("mt.exam.em.EmNee.selectNewExamStudentChk2", reqParam);

    setResponse(model, Arrays.asList(resList1, resList2));
}
카테고리미분류

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다