본문 바로가기

IT/스프링 프레임워크

Roo 프로젝트 만들기

반응형

*모든 자료는 docs.spring.io 기반으로 진행됩니다.!!(거의 번역수준으로.....)



이전 글.....

2015/11/02 - [프로그래밍/스프링 프레임워크] - Roo project


2015/11/02 - [프로그래밍/스프링 프레임워크] - Roo Project 2.0 설치방법 + 환경설정



(1) 프로젝트 생성

프로젝트를 생성하기 위해 CMD 창을 열어서 다음과 같이 칩시다


> mkdir pizza > cd pizza pizza>roo

    ____  ____  ____
   / __ \/ __ \/ __ \
  / /_/ / / / / / / /
 / _, _/ /_/ / /_/ /
/_/ |_|\____/\____/    1.2.1.RELEASE [rev 6eae723]


Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
roo>
roo> hint
Welcome to Roo! We hope you enjoy your stay!

Before you can use many features of Roo, you need to start a new project.

To do this, type 'project' (without the quotes) and then hit TAB.

Enter a --topLevelPackage like 'com.mycompany.projectname' (no quotes).
When you've finished completing your --topLevelPackage, press ENTER.
Your new project will then be created in the current working directory.

Note that Roo frequently allows the use of TAB, so press TAB regularly.
Once your project is created, type 'hint' and ENTER for the next suggestion.
You're also welcome to visit http://stackoverflow.com/questions/tagged/spring-roo
for Roo help.
roo>


위와 같이 hint 를 치면 어떻게 해야하는지 나온다.

하라는데로 project ...... 을 치다 

주의할점은 project 다음은 TAB이다..... 스페이스가 아니라



roo> project setup --topLevelPackage com.springsource.roo.pizzashop
Created ROOT/pom.xml
Created SRC_MAIN_RESOURCES
Created SRC_MAIN_RESOURCES/log4j.properties
Created SPRING_CONFIG_ROOT
Created SPRING_CONFIG_ROOT/applicationContext.xml
com.springsource.roo.pizzashop roo>



그 후 JPA를 생성해야한다.


roo> jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY


여기서는 HIBERNATE를 사용했지만 --provider 뒤에 TAB 을 누르면 제공되는 서비스를 출력해준다.

홈페이지에서는 Postgres, MySQL, Microsoft SQL Server, Oracle, DB2, Sybase, H2, Hypersonic 등을 제공한다고는 적혀있다.

그런데.... Oracle, DB2 JDBC 드라이버는 현재 maven 저장소에서 사용 못할수 있다고 적혀있다. ㅠㅠ.......


(2) Entity, Fields 생성


먼저 해야할건 entity jpa 를 만들어야 한다. 


roo> entity jpa --class ~.domain.Topping --testAutomatically


파라미터 --class, --testAutomatically 를 살펴보면 

--class 클래스를 만든다는것이고 ~.domain.MyEntityClassName 의 클래스라는것이다. ~는 만든 프로젝트 --topLevelPackage에 만들어달라는것이다.


이제 field를 만들어 보자........


위의 클래스 제작 명령어를 치면 자동으로 ~.domain.Topping roo> 상태로 바뀌게 된다 .그 후


~.domain.Topping roo> field string --fieldName name --notNull --sizeMin 2


라고 쳐보자


field ---> 필드 생성 명령어
string ---> 필드 자료형
--fieldName --->  field 의 옵션 파라미터
name ---> field의 이름을 name으로 하겠다는것
--notNull, --sizeMin 2 는 field의 옵션 명령어!!!!



어떻게 하는지 알았으니 진행을 위해base, pizza 엔터티랑, 필드를 추가해보자....
entity jpa --class ~.domain.Base --testAutomatically
field string --fieldName name --notNull --sizeMin 2
entity jpa --class ~.domain.Pizza --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field number --fieldName price --type java.lang.Float

위의 작업을 한 다음, Base와 Topping 의 관계를 정해줘야한다. 하나의 피자에는 여러개의 토핑이 올라가때문에 1 (Pizza) : N (Topping) 연결해주자. 
field set --fieldName toppings --type ~.domain.Topping

그리고 피자는 기본 방식(? 여기서는 Base)를 참고해서 만들기에 Pizza와 Base 를 레퍼런스 관게를 갖도록 해주자
field reference --fieldName base --type ~.domain.Base

그럼 이제 피자 주분에 관한 엔터리를 만들어 보자
entity jpa --class ~.domain.PizzaOrder --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field string --fieldName address --sizeMax 30
field number --fieldName total --type java.lang.Float
field date --fieldName deliveryDate --type java.util.Date
field set --fieldName pizzas --type ~.domain.Pizza







'IT > 스프링 프레임워크' 카테고리의 다른 글

스프링 프레임 워크란?  (0) 2015.11.03
Roo Project 2.0 설치방법 + 환경설정  (0) 2015.11.02
Roo project  (0) 2015.11.02
Servlet 이란  (2) 2015.09.24
스프링 프레임워크 3.0 – security 적용  (0) 2015.09.14