メインコンテンツまでスキップ

ユーザー定義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)