Full Stack Web Developer.
Syaku (샤쿠)

Java, JS (ES6+), Spring, Spring security, jQuery, Reactjs, Bootstrap.

        

09-29 22:34


Spring Boot 2 보기 Front-end 보기 DevOps 보기 Spring 3 보기 Spring Security 3 보기

테스트용 코드관리 모듈 개발 #2 ActionMap : Struts2 + iBATIS is Sample

 

Globals 클래스에서 공용 데이터를 관리합니다.

 

CodeAction.java

/**
 * @class CodeAction
 * @brief 코드관리
 *
 * registered date 20090327
 * updated date 20090327
 * programmed by Seok Kyun. Choi. (최석균)
 * http://syaku.tistory.com
 */

package com.xf.modules.code;

import org.apache.log4j.Logger;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import com.ibatis.sqlmap.client.SqlMapClient;

import com.xf.common.*;
import com.xf.modules.code.CodeModel;

public class CodeAction extends ActionSupport {
 
  /**
   * @brief log4j
   */
  private Logger log = Logger.getLogger(CodeAction.class);

  /**
   * @brief 공용변수
   */
  HttpServletRequest request = ServletActionContext.getRequest();
  private Globals globals = Globals.getInstance(request);
  public Globals getGlobals() { return globals; }
  public void setGlobals(Globals globals) { this.globals = globals; }

  /**
   * @brief iBatis 코드관리 맵핑
   */
  private static SqlMapClient conn = Conn.getInstance("com/xf/modules/code/CodeSqlMap.xml");

  /**
   * @brief 코드관리 모델
   */
  private CodeModel code;
  public CodeModel getCode() { return code; }
  public void setCode(CodeModel code) { this.code = code; }

  /**
   * @brief 코드관리 모델 : 리스트
   */
  private List codeList;
  public List getCodeList() { return codeList; }
  public void setCodeList(List codeList) { this.codeList = codeList; }

  /**
   * @brief 코드관리 최초 실행
   */
  private String mod;
  public String execute() throws Exception {
    mod = globals.getMod();

    // begin list
    if (mod.equals("list")) {
      // list total count
      globals.setTotalCount((Integer) conn.queryForObject("select-code-count",null));
      globals.getPageIndex();
      log.debug("@페이지 인덱스 처리");
      log.debug("페이지 번호: " + globals.getPage());
      log.debug("페이지 행수: " + globals.getPageRow());
      log.debug("페이지 링크수: " + globals.getPageLink());
      log.debug("데이터 총수: " + globals.getTotalCount());
      log.debug("페이지 총수: " + globals.getTotalPage());
      log.debug("페이지 시작 번호: " + globals.getStartPage());
      log.debug("페이지 현재 번호: " + globals.getNowPage());
      log.debug("페이지 끝 번호: " + globals.getEndPage());
      log.debug("시작 인덱스: " + globals.getStartIdx());
      log.debug("가상 번호: " + globals.getVirtualIdx());
      codeList = CodeAdminList();
     
      return "list";

    // begin input
    } else if (mod.equals("input")) {
      code = CodeAdminInput();
      return "input";

    // begin execute
    } else {
      return CodeAdminExec();
    }
  }

  /**
   * @brief 코드관리 목록 : 관리자
   */
  public List CodeAdminList() throws Exception {
    int start_idx = globals.getStartIdx();
    return (List) conn.queryForList("select-code",null,globals.getStartIdx(),globals.getPageRow());
  }

  /**
   * @brief 코드관리 입력 폼 : 관리자
   */
  public CodeModel CodeAdminInput() throws Exception {

    // io update
    if (code != null) {
      globals.setMod("update");
      return (CodeModel) conn.queryForObject("select-code",code);
   
    // io insert
    } else {
     globals.setMod("insert");
     return null;
    }
  }

  /**
   * @brief 코드관리 실행 처리 : 관리자
   */
  public String CodeAdminExec() throws Exception {
   
    // exec insert
    if (mod.equals("insert")) { conn.insert("insert-code",code); }

    // exec update
    else if (mod.equals("update")) { conn.delete("update-code",code); }

    // exec delete
    else if (mod.equals("delete")) { conn.delete("delete-code",code); }
   
    return SUCCESS;
  }
}

written by Seok Kyun. Choi. 최석균.
http://www.cyworld.com/syaku
http://syaku.tistory.com

댓글 남기기
◀ PREV 1···4567891011 NEXT ▶