본문으로 건너뛰기
버전: 3.4.4

사용자정의Dao

BXI의 기본 Dao외의 필요한 테이블을 사용하도록 Dao를 설정할 수 있다.

Dao구성

  1. bxi.extensionbxi.extension.dao 패키지 하단에 Dao인터페이스와, 해당 인터페이스와 매핑하여 사용할 쿼리를 작성한 Mybatis XML 파일을 작성한다.
  2. bxi.extension.dao.dto 패키지 아래에 해당 테이블의 DTO클래스를 빈즈 패턴으로 구현한다.
bxi.extension.dao.BxiInstDao.java
package bxi.extension.dao;
import java.util.List;
import bxi.extension.dao.dto.BxiInstIO;

public interface BxiInstDao {
public List<BxiInstIO> selectBxiInstList(BxiInstIO bxiInst);
public BxiInstIO selectBxiInst(BxiInstIO bxiInst);
public int insertBxiInst(BxiInstIO bxiInst);
public int updateBxiInst(BxiInstIO bxiInst);
public int deleteBxiInst(BxiInstIO bxiInst);
}
bxi.extension.dao.BxiInstDao.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="bxi.extension.dao.BxiInstDao">
<select id="selectBxiInstList" parameterType="bxi.extension.dao.dto.BxiInstIO" resultType="bxi.extension.dao.dto.BxiInstIO">
SELECT
TENANT_ID AS tenantId
,INST_CD AS instCd
,INST_NM AS instNm
,INST_DSCD AS instDscd
,INST_ADDR AS instAddr
,INST_ZIP AS instZip
,TEL_NO AS telNo
,FAX_NO AS faxNo
,INST_RMK AS instRmk
,DEL_YN AS delYn
,LAST_CHNG_DTM AS lastChngDtm
,LAST_CHNG_GUID AS lastChngGuid
FROM BXI_INST
WHERE TENANT_ID = #{tenantId}
AND DEL_YN != 'Y'
</select>

<select id="selectBxiInst" parameterType="bxi.extension.dao.dto.BxiInstIO" resultType="bxi.extension.dao.dto.BxiInstIO">
SELECT
TENANT_ID AS tenantId
,INST_CD AS instCd
,INST_NM AS instNm
,INST_DSCD AS instDscd
,INST_ADDR AS instAddr
,INST_ZIP AS instZip
,TEL_NO AS telNo
,FAX_NO AS faxNo
,INST_RMK AS instRmk
,DEL_YN AS delYn
,LAST_CHNG_DTM AS lastChngDtm
,LAST_CHNG_GUID AS lastChngGuid
FROM BXI_INST
WHERE TENANT_ID = #{tenantId}
AND INST_CD = #{instCd}
AND DEL_YN != 'Y'
</select>
</mapper>

Dao사용

스프링 빈 클래스에서 사용하는 경우

@Component
public class BasicDbToFileProcessor implements DbToFileProcess {
private Logger logger = LoggerFactory.getLogger(getClass());

@Autowired
private BxiInstDao bxiInstDao;
}

일반 java 클래스에서 사용하는 경우

bxi.common.context.BeanManager를 사용한다.

BeanManager.getBean("bxiInstDao", BxiInstDao.class)