상위 질문
타임라인
채팅
관점

마이바티스

자바 퍼시스턴스 프레임워크 위키백과, 무료 백과사전

Remove ads

마이바티스(MyBatis)는 자바 퍼시스턴스 프레임워크의 하나로 XML 서술자나 애너테이션(annotation)을 사용하여 저장 프로시저SQL 문으로 객체들을 연결시킨다.

간략 정보 개발자, 안정화 버전 ...

마이바티스는 아파치 라이선스 2.0으로 배포되는 자유 소프트웨어이다.

마이바티스는 IBATIS 3.0의 포크이며 IBATIS의 원 개발자들이 포함된 팀에 의해 유지보수되고 있다.

Remove ads

사용법

SQL 문은 XML 파일이나 애너테이션에 저장되어 있다. 아래는 마이바티스 매퍼를 기술하며 일부 마이바티스 애너테이션이 있는 자바 인터페이스를 구성한다:

package org.mybatis.example;

public interface BlogMapper {
    @Select("select * from Blog where id = #{id}")
    Blog selectBlog(int id);
}

위의 문은 다음과 같이 실행된다.

BlogMapper mapper = session.getMapper(BlogMapper.class);
Blog blog = mapper.selectBlog(101);

SQL 문들과 매핑들은 다음과 같이 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="org.mybatis.example.BlogMapper">
    <select id="selectBlog" parameterType="int" resultType="Blog">
        select * from Blog where id = #{id}
    </select>
</mapper>

문들은 마이바티스 API를 사용하여 실행할 수도 있다.

Blog blog = session.selectOne("org.mybatis.example.BlogMapper.selectBlog", 101);

더 자세한 사항은 마이바티스 사이트의 사용자 안내서를 참조할 것. (외부 링크)

Remove ads

같이 보기

각주

외부 링크

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads