Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ICE4에서 Mybatis를 사용하기위한 기본 가이드

...

Application yml

활성화된 profile 의 application yml 파일에 Mybatis mapper classpath가 설정되어 있어야 한다.

Info

src/main/resources/application-{active profile name}.yml

application-dxp-loc.yml

...

Info

src/main/resources/schema/profiles/{active profile name}/datasource.json

Field

Description

typeId

datasource 값 고정

id

datasource ID

ssl

ssl 여부

true / false

dsName

datasource 이름

jdbcUrl

DB url

dbType

DB 유형

Oracle, MySQL, Maria, MS-SQL 지원

CODE

  • oracle

  • mysql

  • maria

  • mssql

username

DB user ID

password

DB user Password

...

Code Block
@Autowired
private MybatisService mybatisService;
private SqlSessionTemplate sqlSessionTemplate;

public SqlSessionTemplate getSessionTemplate() {
    if (sqlSessionTemplate == null) {
        sqlSessionTemplate = mybatisService.getSqlSessionTemplate("oracleDb");
    }
    return sqlSessionTemplate;
}

public List<Map<String, Object>> list(QueryContext context) {
    List<Map<String, Object>> list = getSessionTemplate().selectList("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list");
    return list;
}

LogicRepository

  • "NodeType의 repositoryType": "logic""serviceName": "sampleLogicMybatisService"logic 유형으로 Mybatis로 SQL 실행 및 반환된 결과를 사용하는데 활용할 수 있다.

  • serviceName(LogicRepository를 implement하는 서비스명)을 설정

  • 기본적인 CRUD 및 List API 호출시에 해당 서비스를 호출하여 처리된 결과 반환

src/main/resources/schema/test/sampleLogicMybatisSchema.json
Code Block
[
  {
    "tid": "sampleLogicMybatis",
    "parentId": "test",
    "typeId": "nodeType",
    "repositoryType": "logic",
    "microservice": "test",
    "typeName": "Sample Logic Mybatis",
    "serviceName": "sampleLogicMybatisService",
    "propertyTypes":[
      ...
    ]
  }
]

  • @Service annotation 설정 : nodeType의 serviceName과 동일

@Service("sampleLogicMybatisService")

...

src/main/java/net/ion/ice/test/SampleLogicMybatisService.java
Code Block
@Service("sampleLogicMybatisService")
public class SampleLogicMybatisService implements LogicRepository {
    @Autowired
    private MybatisService mybatisService;
    private SqlSessionTemplate sqlSessionTemplate;

    public SqlSessionTemplate getSessionTemplate() {
        if (sqlSessionTemplate == null) {
            sqlSessionTemplate = mybatisService.getSqlSessionTemplate("oracleDb");
        }

        return sqlSessionTemplate;
    }

    @Override
    public List<Map<String, Object>> list(QueryContext context) {
        List<Map<String, Object>> list = getSessionTemplate().selectList("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list");
        return list;
    }

    @Override
    public Map<String, Object> read(String id) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("id", id);
        Map<String, Object> result = getSessionTemplate().selectOne("net.ion.ice.services.mybatis.mapper.SampleLogicMybatis.list", map);
        return result;
    }

    @Override
    public int create(Node node) {
        return 0;
    }

    @Override
    public int update(Node node) {
        return 0;
    }

    @Override
    public int delete(String id) {
        return 0;
    }
}

...