@Springfield - Basic

Code

package com.u2ware.springfield.sample.part1.step2;

import javax.persistence.Entity;
import javax.persistence.Id;

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.JPA
)
@Entity
public @ToString class JpaBean {

	@Id
	@Getter @Setter private String id;
	@Getter @Setter private String password;
	@Getter @Setter private String name;
	@Getter @Setter private Integer age;
}
		

Beans

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

bean name bean type bean implement
"jpaBeanController"EntityController<JpaBean, JpaBean>com.u2ware.springfield.controller. EntityHandler
"jpaBeanValidator" EntityValidator<JpaBean, JpaBean> com.u2ware.springfield.validation. EntityValidatorImpl
"jpaBeanService" EntityService<JpaBean, JpaBean> com.u2ware.springfield.service. EntityServiceImpl
"jpaBeanRepository"EntityRepository<JpaBean, String>com.u2ware.springfield.repository.jpa. EntityJpaRepository

RequestMapping

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

매핑 경로 HTTP Method Controller Method 이름 예제 Command 객체 예제 매핑 경로
/{topLevelMapping}/ GET home() JpaBean/part1/step2/
/{topLevelMapping} GET findForm() JpaBean/part1/step2
/{topLevelMapping} POST find() JpaBean/part1/step2
/{topLevelMapping}/{id} GET read() JpaBean/part1/step2/bar
/{topLevelMapping}/new GET createForm()JpaBean/part1/step2/new
/{topLevelMapping}/new POST create() JpaBean/part1/step2/new
/{topLevelMapping}/{id}/editGET updateForm()JpaBean/part1/step2/bar/eidt
/{topLevelMapping}/{id}/editPUT update() JpaBean/part1/step2/bar/eidt
/{topLevelMapping}/{id}/editDELETEdelete() JpaBean/part1/step2/bar/eidt
Note:
@Springfield 는 @javax.persistence.Id 가 선언된 bean property 를 RequestMapping 의 {id}에 매핑한다.
Note:
@Springfield 의 topLevelMapping 속성에 별도의 선언 이 없으면, basePackage 를 기준으로 결정된다.
예제에서 basePackage 는 com.u2ware.springfield.sample 이므르 예제에서 topLevelMapping 은 /part1/step2 이 된다.

JPA

Reference
JPA
spring-data-jpa
application-context.properties:

jpa 설정

orm.jpa.defaultPersistenceUnitName=em
orm.jpa.hibernate.dialect=org.hibernate.dialect.HSQLDialect
#orm.jpa.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#orm.jpa.hibernate.hbm2ddl.auto=validate
orm.jpa.hibernate.hbm2ddl.auto=update
orm.jpa.hibernate.show_sql=true
orm.jpa.hibernate.format_sql=true