Grails 约束 GORM-JPA 始终按字母顺序排序
在我使用 GORM-JPA 的 grails 应用程序中,我无法使用约束定义类元素的顺序。如果我自动生成视图,它们都会按字母顺序排序,而不是按定义的顺序排序。这是我的源类:
package kbdw
import javax.persistence.*;
// import com.google.appengine.api.datastore.Key;
@Entity
class Organisatie implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id
@Basic
String naam
@Basic
String telefoonnummer
@Basic
String email
@Basic
OrganisatieType type
@Basic
String adresLijnEen
@Basic
String adresLijnTwee
@Basic
String gemeente
@Basic
String postcode
@Basic
String faxnummer
static constraints = {
id visible:false
naam size: 3..75
telefoonnummer size: 4..18
email email:true
type blank:false
adresLijnEen size:5..250
adresLijnTwee blank:true
gemeente size: 2..100
postcode size: 4..10
faxnummer size: 4..18
}
}
enum OrganisatieType {
School,
NonProfit,
Bedrijf
}
变量名称是荷兰语,但应该很清楚(Organisatie = 组织,naam = 名称,adres = 地址,...)。
如何强制应用程序使用该属性顺序?需要使用@注解吗?
谢谢你!
伊万 (ps:它用于部署在 Google App Engine 上;-))
In my grails app, in which I use GORM-JPA, I cannot define the order of the elements of the class using the constraints. If I autogenerate the views, they are all sorted alphabetically, instead of the defined order. Here's my source class:
package kbdw
import javax.persistence.*;
// import com.google.appengine.api.datastore.Key;
@Entity
class Organisatie implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id
@Basic
String naam
@Basic
String telefoonnummer
@Basic
String email
@Basic
OrganisatieType type
@Basic
String adresLijnEen
@Basic
String adresLijnTwee
@Basic
String gemeente
@Basic
String postcode
@Basic
String faxnummer
static constraints = {
id visible:false
naam size: 3..75
telefoonnummer size: 4..18
email email:true
type blank:false
adresLijnEen size:5..250
adresLijnTwee blank:true
gemeente size: 2..100
postcode size: 4..10
faxnummer size: 4..18
}
}
enum OrganisatieType {
School,
NonProfit,
Bedrijf
}
The variable names are in Dutch, but it should be clear (Organisatie = organisation, naam = name, adres = address, ...).
How do I force the app to use that order of properties? Do I need to use @ annotations?
Thank you!
Yvan
(ps: it's for deploying on the Google App Engine ;-) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试安装和黑客脚手架,并使用
gsp-s 中的 DomainClassPropertyComparator
。支架模板在默认比较器上执行 Collections.sort(),但您可以使用显式比较器。缺少 Hibernate 可能是原因:没有它,DomainClassPropertyComparator 将无法工作,Grails 使用 SimpleDomainClassPropertyComparator - 我正在查看 DefaultGrailsTemplateGenerator.groovy
你可以,当然,提供另一个比较器来比较声明字段的顺序。
编辑:
例如,安装脚手架后,我有一个文件
\src\templates\scaffolding\edit.gsp
。里面有这样几行:其中
comparator
是 Grails 脚手架提供的变量。你可以这样做:其中 PropComparator 类似于
Try installing and hacking scaffolding, and use
DomainClassPropertyComparator
in your gsp-s. Scaffold templates do a Collections.sort() on default comparator, but you can use explicit one.The absence of Hibernate might be the cause: without it,
DomainClassPropertyComparator
won't work, and Grails usesSimpleDomainClassPropertyComparator
- I'm looking at DefaultGrailsTemplateGenerator.groovyYou can, for sure, provide another
Comparator
that will compare the order of declared fields.EDIT:
For example, after installing scaffolding I have a file
<project root>\src\templates\scaffolding\edit.gsp
. Inside, there are such lines:where
comparator
is variable provided by Grails scaffolding. You can do:where PropComparator is something like