package com.u2ware.springfield.sample.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 { @Getter @Setter private String id; @Getter @Setter private String password; @Getter @Setter private String name; @Getter @Setter private Integer age; }
<?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="com.u2ware.springfield.sample.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(strategy=Strategy.SQLSESSION) 선언으로 다음 4개의 Bean 이 자동 생성, 등록 된다.
bean name | bean type | bean implement |
---|---|---|
"mybatisBeanController" | EntityController<MybatisBean, MybatisBean> | com.u2ware.springfield.controller. EntityHandler |
"mybatisBeanValidator" | EntityValidator<MybatisBean, MybatisBean> | com.u2ware.springfield.validation. EntityValidatorImpl |
"mybatisBeanService" | EntityService<MybatisBean, MybatisBean> | com.u2ware.springfield.service. EntityServiceImpl |
"mybatisBeanRepository" | EntityRepository<MybatisBean, String> | com.u2ware.springfield.repository.sqlsession. EntitySqlsessionRepository |
CRUD 를 기본으로 한 EntityController 의 9 개 method 를 RequestMapping 한다.
매핑 경로 | HTTP Method | Controller Method 이름 | 예제 Command 객체 | 예제 매핑 경로 |
---|---|---|---|---|
/{topLevelMapping}/ | GET | home() | MybatisBean | /part1/step1/ |
/{topLevelMapping} | GET | findForm() | MybatisBean | /part1/step1 |
/{topLevelMapping} | POST | find() | MybatisBean | /part1/step1 |
/{topLevelMapping}/{id} | GET | read() | MybatisBean | /part1/step1/foo |
/{topLevelMapping}/new | GET | createForm() | MybatisBean | /part1/step1/new |
/{topLevelMapping}/new | POST | create() | MybatisBean | /part1/step1/new |
/{topLevelMapping}/{id}/edit | GET | updateForm() | MybatisBean | /part1/step1/foo/eidt |
/{topLevelMapping}/{id}/edit | PUT | update() | MybatisBean | /part1/step1/foo/eidt |
/{topLevelMapping}/{id}/edit | DELETE | delete() | MybatisBean | /part1/step1/foo/eidt |
@Springfield 는 패턴에 맞는 파일을 찾아 sql mapping 한다.