field系コマンド
- クラスのフィールドを追加する
共通オプション
--fieldName [fieldName] (必須)
- フィールド名を[name]に指定する
--class [className]
- フィールドのクラスを[className]に指定する
--notNull
- notNull制約のアノテーション(@notNull)が付与される
- --nullRequiredオプションと同時に指定しても、両方とも定義される(特に怒られない)
--nullRequired
- null制約のアノテーション(@null)が付与される
- --notNullオプションと同時に指定しても、両方とも定義される(特に怒られない)
--comment
- [className]_Roo_ToString.ajファイルのtoString()メソッドに、コメントが付与される
- フィールド宣言等のJavaDocコメントには付与されない
roo> field string --fieldName foo --comment bar --class ~.RooClass
Managed SRC_MAIN_JAVA\com\example\sandbox\RooClass_Roo_ToString.aj public String RooClass.toString() { StringBuilder sb = new StringBuilder(); sb.append("Foo: ").append(getFoo()); return sb.toString(); }
--transient
- フィールド宣言にtransientを付ける
--permitReservedWords
- 名前に予約語を使えるようにする
roo> field date --fieldName date --type java.util.Date Reserved SQL keyword 'date' is not permitted as symbol name roo> field date --fieldName date --type java.util.Date --permitReservedWords Managed SRC_MAIN_JAVA\com\example\sandbox\domain\SandboxEntity.java ...
field dateコマンドオプション
- 日付時刻用のフィールドを追加する
--type [typeName] (必須)
- [typeName]にはjava.util.Calendar, java.util.Dateか、それぞれの派生クラスを指定する
- エンティティクラスに対して--typeにjava.util.Date, java.util.Calendar以外を指定するとエラーになるっぽい(MyDateはjava.util.Dateの派生クラス)
roo> focus --class ~.domain.SandboxEntity roo> field date --fieldName registrationDate --type ~.MyDate Managed SRC_MAIN_JAVA\com\example\sandbox\domain\SandboxEntity.java Managed SRC_MAIN_JAVA\com\example\sandbox\domain\SandboxEntity_Roo_JavaBean.aj Undo manage SRC_MAIN_JAVA\com\example\sandbox\domain\SandboxEntity_Roo_JavaBean.aj Undo manage SRC_MAIN_JAVA\com\example\sandbox\domain\SandboxEntity.java Method '[DefaultMethodMetadata@1069691 declaredByMetadataId = 'MID:org.springframework.roo.addon.web.mvc.controller.WebScaffoldMetadata#SRC_MAIN_JAVA?com.example.sandbox.web.SandboxEntityController', modifier = 'public', methodName = populateMyDates parameterTypes = list[[empty]], parameterNames = list[[empty]], returnType = java.util.Collection<com.example.sandbox.MyDate>, annotations = list[[DefaultAnnotationMetadata@1871d9b annotationType = org.springframework.web.bind.annotation.ModelAttribute, attributes = list[value -> mydates]]], throwsTypes = list[[empty]], body = '']' failed to provide a body, despite being identified for ITD inclusion roo> focus --class ~.SandboxClass roo> field date --fieldName registrationDate --type ~.MyDate Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java
--persistenceType [persistenceType]
--future
- 未来の日付時刻であるかの検証を行うようにする
--past
- 過去の日付時刻であるかの検証を行うようにする
- @Pastアノテーションが付与される
--dateFormat [formatType]
--timeFormat [formatType]
- @DateTimeFormatアノテーションを付与する
- [formatType]にはMEDIUM, NONE, SHORTのいずれかを指定する
field date --fieldName mmDate --type java.util.Date --dateFormat MEDIUM --timeFormat MEDIUM Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName msDate --type java.util.Date --dateFormat MEDIUM --timeFormat SHORT Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName mnDate --type java.util.Date --dateFormat MEDIUM --timeFormat NONE Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName smDate --type java.util.Date --dateFormat SHORT --timeFormat MEDIUM Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName ssDate --type java.util.Date --dateFormat SHORT --timeFormat SHORT Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName snDate --type java.util.Date --dateFormat SHORT --timeFormat NONE Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java field date --fieldName nnDate --type java.util.Date --dateFormat NONE --timeFormat NONE Managed SRC_MAIN_JAVA\com\example\sandbox\SandboxClass.java
... @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "MM") private Date mmDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "MS") private Date msDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "M-") private Date mnDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "SM") private Date smDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "SS") private Date ssDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "S-") private Date snDate; @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(style = "--") private Date nnDate; ...
- --dateFormat NONE --timeFormat NONEの組み合わせはおそらく実行時に残念なことになる
- @DateTimeFormatをstyle指定ではなくpattern指定させたい場合は、手で修正することになるっぽい
@DateTimeFormat(pattern = "yyyy年MM月dd日") private Date patternDate;
field numberコマンドオプション
- 数値フィールドを追加する
--type [typeName] (必須)
- 数値クラスに何を使用するかを指定する
java.lang.Byte, java.lang.Double, java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Number, java.lang.Short, java.math.BigDecimal, java.math.BigInteger
--decimalMin [decimalMin]
- BigDecimal, BigIntegerの最小値の検証を行うようにする
- @DecimalMinアノテーションが付与されます
--decimalMax [decimalMax]
- BigDecimal, BigIntegerの最大値の検証を行うようにする
- @DecimalMaxアノテーションが付与されます
--digitsInteger [integer]
--digitsFraction [fraction]
- 整数([integer])の桁数と少数([fraction])の検証を行うようにする
- @Digitsアノテーションが付与されます
--min [min]
- 数値の最小値の検証を行うようにする
- @Minアノテーションが付与されます
--max [max]
- 数値の最大値の検証を行うようにする
- @Maxアノテーションが付与されます
--primitive
- プリミティブ型としてフィールドを追加する
- [typeName]にjava.math.BigDecimal, java.math.BigIntegerを指定していた場合、無視されます
field otherコマンドオプション
- 任意のクラスをフィールドとして追加する
--type [typeName] (必須)
- [typeName]には任意のクラスを指定する
field referenceコマンドオプション
- エンティティクラスへの参照を追加する
--type [typeName]
- [typeName]には任意のエンティティクラスを指定する
--cardinality [cardinality]
--fetch [fetchType]
- [cardinality]にはMANY_TO_ONE, ONE_TO_ONEのどちらかを指定する
- [fetch]にはEAGER(即時ロード), LAZY(遅延ロード)のどちらかを指定する
- @ManyToOneまたは@OneToOneアノテーションが付与される
field setコマンドオプション
- Setクラスのフィールドを作成します
--element [element]
- Setに格納するエンティティクラスを指定する
--sizeMin [sizeMin]
--cardinality [cardinality]
--fetch [fetchType]
--mappedBy [mappedBy]
- [cardinality]にはMANY_TO_MANY, ONE_TO_MANYのどちらかを指定する
- [fetch]にはEAGER(即時ロード), LAZY(遅延ロード)のどちらかを指定する
- [mappedBy]には関連を持っているフィールドを指定する
- @ManyToManyまたは@OneToManyアノテーションが付与される
field stringコマンドオプション
- Stringフィールドを作成する
--decimalMin [decimalMin]
- 数値としての最小値の検証を行うようにする
- @DecimalMinアノテーションが付与される
--decimalMax [decimalMax]
- 数値としての最大値の検証を行うようにする
- @DecimalMaxアノテーションが付与される
--sizeMin [sizeMin]
--sizeMax [sizeMax]
- 文字列の長さの最小値・最大値の検証を行うようにする
- @Sizeアノテーションが付与される
使用例
- あとでkwsk