Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 我想添加一个名为';类别';我的技能领域_Grails - Fatal编程技术网

Grails 我想添加一个名为';类别';我的技能领域

Grails 我想添加一个名为';类别';我的技能领域,grails,Grails,我想在我的技能域中添加一个名为“类别”的字段 *注意:该类别将是一个预先填充的列表 以下是我的技能领域的外观: class Skill { String name String description String skillCode static constraints = { name nullable: false, unique: true description nullable: true skill

我想在我的技能域中添加一个名为“类别”的字段

*注意:该类别将是一个预先填充的列表

以下是我的技能领域的外观:

class Skill {

    String name
    String description
    String skillCode

    static constraints = {
        name nullable: false, unique: true
        description nullable: true
        skillCode nullable: true, unique: true
    }

    static mapping = {
        name type: "text"
        description type: "text"
        skillCode type: "text"
    }

    public String toString() {
        return "${skillCode}. (${name})"
    }


}

最有效的方法是什么?

不确定是否是您想要的方法,但据我所知,您正在寻找以下解决方案

课堂技能{

String name
String description
String skillCode
String category

static constraints = {
    name nullable: false, unique: true
    description nullable: true
    skillCode nullable: true, unique: true
    category inList: ["Python", "Java", "Grails"]
}

static mapping = {
    name type: "text"
    description type: "text"
    skillCode type: "text"
}

public String toString() {
    return "${skillCode}. (${name})"
}
}


“我想在我的技能域中添加一个名为“Category”的字段”-该字段必须被称为
Category
,还是可以被称为
Category
(这会有所不同)。在代码(枚举)中预填充,还是通过将值保存到Category域对象中预填充?@JeffScottBrown对于Python、Java、,Grails是技能,但属于编程范畴Languages@Daniel你能详细解释一下你的解释吗?我的问题是得到关于如何最好地实现这一点的澄清,但现在听起来你更多的是问
Category
vs
Category
。我强烈建议遵循最佳实践(总是很重要,但在grails中更为重要),并将其命名为
category
全小写。在问题下方的一条评论中,Sparsh提到字段名必须是
category
,不能是
category
。对这一点的解释对我来说没有意义,但这是明确的要求。如果在您的示例中将
类别
更改为
类别
,而不进行更多更改,您将遇到其他问题。您不太理解您试图解释的内容。我只是根据我的理解回答。