【问题标题】:Spring roo, field enumSpring roo,字段枚举
【发布时间】:2011-02-28 13:02:01
【问题描述】:

我是 Spring MVC 和 Spring Roo 的新手。

什么是字段枚举?

如何枚举所有允许的值?

是使用查找表还是检查约束来实现?

【问题讨论】:

    标签: java spring-mvc spring-roo


    【解决方案1】:

    Roo 的field enum --fieldName --type 命令添加了一个指定枚举类型的私有字段。

    您可以手动创建枚举类型或使用 roo 命令:

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

    这将创建一个 Colors 枚举:

    public Enum Colors {
      BLAU, VERMELL
    }
    

    那么就可以使用then枚举类型来定义一个实体字段了:

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

    这将定义 Foo 实体:

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

    有关 roo 命令的完整参考,请参阅 http://static.springsource.org/spring-roo/reference/html/command-index.html

    【讨论】:

    • 优秀的答案。谢谢!
    【解决方案2】:

    如果您打算使用 GWT 或类似的东西,您可能希望将 Colors 类放在共享包中,因为客户端和服务器都使用枚举类。 所以你会这样做:enum type --class ~.shared.Colors

    【讨论】:

      猜你喜欢
      • 2015-08-22
      • 2018-10-21
      • 2017-08-24
      • 1970-01-01
      • 2021-12-22
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多