Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring roo, field enum

I'm new to Spring MVC and Spring Roo.

What is field enum?

How can I enumerate all allowed values?

Is it implemented using lookup table or check constraint?

like image 599
Emir Avatar asked Feb 28 '11 13:02

Emir


2 Answers

Roo's field enum --fieldName --type command adds a private field of the specified enum type.

You can create the enum type by hand or use roo commands:

roo> enum type --class ~.domain.Colors
roo> enum constant --name BLAU
roo> enum constant --name VERMELL

This creates a Colors enum:

public Enum Colors {
  BLAU, VERMELL
}

Then you can use then enum type to define an entity field:

roo> entity --class ~.domain.Foo
roo> field enum --fieldName color --type ~.domain.Colors

This will define the Foo entity:

//Annotations and imports ommited for brevity
public class Foo{
     private Colors color;
}

See http://static.springsource.org/spring-roo/reference/html/command-index.html for a complete reference of the roo commands.

like image 123
Serxipc Avatar answered Oct 16 '22 18:10

Serxipc


If you are going to use GWT or something similar you probably want to place the Colors class inside the shared package because enum classes are used by both the client and the server. So you will do: enum type --class ~.shared.Colors

like image 2
madmed Avatar answered Oct 16 '22 17:10

madmed