Data Access

MybatisBean

package example.u2ware.springfield.part1.step1;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.u2ware.springfield.config.Springfield;
import com.u2ware.springfield.config.Springfield.Strategy;

@Springfield(
        strategy=Strategy.SQLSESSION,
        identity={"id"}
)
public @ToString class MybatisBean {

        private @Getter @Setter Integer id;
        private @Getter @Setter String password;
        private @Getter @Setter String name;
        private @Getter @Setter String address;
}

MybatisBean.sqlsession.xml

<mapper namespace="example.u2ware.springfield.part1.step1.MybatisBean">

        <select id="exists"> .... </select>

        <insert id="create"> .... </insert>

        <select id="read"> .... </select>

        <update id="update"> .... </update>

        <delete id="delete"> .... </delete>

        <select id="findAll"> .... </select>

        <select id="findAllCount"> .... </select>

</mapper>

@Springfield

@Springfield(strategy=Strategy.SQLSESSION) 선언으로 다음 3개의 Bean 이 자동 생성, 등록 된다.

bean namebean typebean implement
"mybatisBeanController" EntityController<MybatisBean, MybatisBean> com.u2ware.springfield.controller. EntityHandler
"mybatisBeanService" EntityService<MybatisBean, MybatisBean> com.u2ware.springfield.service. EntityServiceImpl
"mybatisBeanRepository" EntityRepository<MybatisBean, Integer> com.u2ware.springfield.repository.sqlsession. EntitySqlsessionRepository
application-context.properties:
Springfield 는 패턴에 맞는 파일을 찾아 sql mapping 한다.

orm.sqlsession.configLocation=
orm.sqlsession.mapperLocationsPattern=/**/*.sqlsession.xml

Reference:
Mybatis\

RequestMapping

EntityController 는 CRUD 를 기본으로 한 9 개의 method 에 RequestMapping 한다.

매핑 경로HTTP MethodController Method 이름예제 Command 객체예제 매핑 경로
/{topLevelMapping}/GEThomeMybatisBean/part1/step1/
/{topLevelMapping}GETfindFormMybatisBean/part1/step1
/{topLevelMapping}POSTfindMybatisBean/part1/step1
/{topLevelMapping}/{id}GETreadMybatisBean/part1/step1/7
/{topLevelMapping}/newGETcreateFormMybatisBean/part1/step1/new
/{topLevelMapping}/newPOSTcreateMybatisBean/part1/step1/new
/{topLevelMapping}/{id}/editGETupdateFormMybatisBean/part1/step1/7/eidt
/{topLevelMapping}/{id}/editPUTupdateMybatisBean/part1/step1/7/eidt
/{topLevelMapping}/{id}/editDELETEdeleteMybatisBean/part1/step1/7/eidt
Note:
@Springfield 의 identity 속성값은 RequestMapping 의 {id} 를 결정하는 용도로 사용한다.
Note:
topLevelMapping 은 별도의 선언 이 없으면, basePackage 를 기준으로 결정된다.
예제에서 basePackage 는 example.u2ware.springfield 이므르 예제에서 topLevelMapping 은 /part1/step1 이 된다.