package com.u2ware.springfield.sample.part3.step3; import lombok.Getter; import lombok.Setter; import com.u2ware.springfield.config.Springfield; import com.u2ware.springfield.config.Springfield.Strategy; @Springfield( strategy=Strategy.DTO, identity={"id"} ) public class FormBean { @Getter @Setter private String id; @Getter @Setter private Integer age; }
package com.u2ware.springfield.sample.part3.step3; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.u2ware.springfield.domain.EntityPageImpl; import com.u2ware.springfield.domain.EntityPageable; import com.u2ware.springfield.repository.EntityRepository; import com.u2ware.springfield.sample.part3.step1.TargetBean; import com.u2ware.springfield.service.EntityService; @Service public class FormBeanService implements EntityService<FormBean, FormBean>{ protected final Log logger = LogFactory.getLog(getClass()); @Autowired @Qualifier("targetBeanRepository") protected EntityRepository<TargetBean, String> targetBeanRepository; @Override @Transactional public Iterable<?> findForm(FormBean query, EntityPageable pageable) { return find(query, pageable); } @Override @Transactional public Iterable<?> find(FormBean query, EntityPageable pageable) { if(pageable != null && pageable.isEnable()){ return new EntityPageImpl<TargetBean>(targetBeanRepository.findAll(query, pageable)); }else{ return targetBeanRepository.findAll(query, pageable); } } @Override public Object home(FormBean query) { return query; } @Override public FormBean createForm(FormBean entity) { return entity; } @Override public FormBean updateForm(FormBean entity) { return entity; } @Override @Transactional public FormBean read(FormBean entity) { TargetBean target = targetBeanRepository.read(entity.getId()); entity.setId(target.getId()); entity.setAge(target.getAge()); return entity; } @Override @Transactional public FormBean create(FormBean entity) { TargetBean target = new TargetBean(); target.setId(entity.getId()); target.setPassword("password"+entity.getId()); target.setName("name"+entity.getId()); target.setAge(entity.getAge()); targetBeanRepository.create(target); return entity; } @Override @Transactional public FormBean update(FormBean entity) { TargetBean target = targetBeanRepository.read(entity.getId()); target.setId(entity.getId()); target.setAge(entity.getAge()); return entity; } @Override @Transactional public FormBean delete(FormBean entity) { targetBeanRepository.delete(entity.getId()); return entity; } }
@Springfield(strategy=Strategy.DTO) 선언으로 다음 3개의 Bean 이 등록 된다.선언으로 다음 3개의 Bean 이 등록 된다. 자동생성 하려는 Bean(Name)이 이미 존재한다면, @Springfield 는 Bean 을 따로 생성하지 않는다.
bean name | bean type | bean implement |
---|---|---|
"formBeanController" | EntityController<FormBean, FormBean> | com.u2ware.springfield.controller. EntityHandler |
"formBeanValidator" | EntityValidator<FormBean, FormBean> | com.u2ware.springfield.validation. EntityValidatorImpl |
"formBeanService" | EntityService<FormBean, FormBean> | com.u2ware.springfield.sample.part3.step3. FormBeanService |
매핑 경로 | HTTP Method | Controller Method 이름 | 예제 Command 객체 | 예제 매핑 경로 |
---|---|---|---|---|
/{topLevelMapping}/ | GET | home() | FormBean | /part3/step3/ |
/{topLevelMapping} | GET | findForm() | FormBean | /part3/step3 |
/{topLevelMapping} | POST | find() | FormBean | /part3/step3 |
/{topLevelMapping}/{id} | GET | read() | FormBean | /part3/step3/baz |
/{topLevelMapping}/new | GET | createForm() | FormBean | /part3/step3/new |
/{topLevelMapping}/new | POST | create() | FormBean | /part3/step3/new |
/{topLevelMapping}/{id}/edit | GET | updateForm() | FormBean | /part3/step3/baz/eidt |
/{topLevelMapping}/{id}/edit | PUT | update() | FormBean | /part3/step3/baz/eidt |
/{topLevelMapping}/{id}/edit | DELETE | delete() | FormBean | /part3/step3/baz/eidt |
@Springfield(strategy=Strategy.DTO) 에 의해 생성된 EntityService 는 EntityRepository 를 주입 받지 않는다.