Controller 예제

개발자는 MiPlatform환경에서 AnyframeFormController대신 AnyframeMiController를 이용한다.
이 장에서는 조회/저장 시 Controller클래스를 어떻게 작성하는지 설명한다.

조회

AnyframeMiController의 조회

public class GetCategoryListMIController extends AnyframeMiController {
  
  private CategoryService categoryService = null;

  public void setCategoryService(CategoryService categoryService) {
      this.categoryService = categoryService;
  }
  
  public void operate(HttpServletRequest request, VariableList inVl,
            DatasetList inDl, VariableList outVl, DatasetList outDl)
            throws Exception {

//조회 조건 및 조회에 필요한 값을 VO에 세팅 함
//(MIPSQLService사용 시  inVl, inDl을 VO에 세팅 안하고 바로 사용 할 수 있다.)
    SearchVO searchVO = new SearchVO();
    searchVO.setSearchCondition(inVl.getValueAsString("searchCondition"));
    searchVO.setSearchKeyword(inVl.getValueAsString("searchKeyword"));
    searchVO.setSearchUseYn(inVl.getValueAsString("searchUseYn"));

//Biz. Service 호출
<!-- 중략 -->
    
    if (resultList == null || resultList.size() < 1) {
            throw new Exception("데이터가 없습니다.");
        } else {
//MIPSQLService의 search()메소드를 이용한 조회는 return 타입이 Dataset이므로 데이터 변환이 불필요함.
          outDl.addDataset("ds_access", 
              this.convertVoListToDataset("ds_access", resultList, true));
        }
  }
}
Client -> Server parameter전달

Client에서 Get방식으로 전달한 parameter를 VariableList inVl에서 getValueAsString()함수를 이용하며 추출 가능하다.
*MIPSQLService의 search메소드를 이용해 조회 할 경우에는 argument로 VariableList, Dataset을 직접 사용 할 수 있다.

Server-> Client 조회Data전달

VO, VO List를 convertVoListToDataset()메소드를 이용하여 Dataset객체로 전환 후 DatasetList outDl 에 입력하여 전달한다.
*MIPSQLService의 search메소드의 return 타입은 Dataset이므로 MIPSQLService를 이용한 조회 시에는 VO객체를 Dataset로 변환이 불필요하다.

저장

AnyframeMiController의 저장

public class UpdateCategoryMIController extends AnyframeMiController {

    private CategoryService categoryService = null;

    public void setCategoryService(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    public void operate(HttpServletRequest request, VariableList inVl,
            DatasetList inDl, VariableList outVl, DatasetList outDl)
            throws Exception {
        Dataset ds = inDl.getDataset("ds_input");
        
//MIPSQLService의 update()메소드를 이용한 저장 시에는 Dataset을 Map으로 변환할 필요가 없다.
        HashMap changeMap = convertDatasetToListMap(Category.class, ds);
        
//Biz. Service 호출
        categoryService.processAll(changeMap);
    }
}
Client -> Server 변경Data전달

Client에서 post방법으로 전달 된 Dataset을 convertDatasetToListMap() 메소드를 이용하여 유형별 VO List가 담긴 HashMap객체로 전환할 수 있으며
HashMap객체는 “insert”,”update”,”delete”를 Key로 각각 유형별 VO List를 갖고 있다.
*MIPSQLService의 update()메소드는 Dataset을 argument로 직접 사용 할 수 있으므로 VO List가 담긴HashMap객체로 변환이 불필요하다.