Grails 新手 - 脚手架问题 - 将唯一 id 替换为可读值?
我正在使用 grails 创建一个 Web 应用程序,并且正在使用 Scaffold 开发 CRUD 原型。开箱即用,脚手架将使用唯一 id(这是有意义的)作为外键值,我想知道是否可以轻松地将唯一 id 替换为可读值(例如所述表中两个值的组合) )。
例如: 我有 Location 和 RoomNumber 域,分别代表酒店位置和房间号。因此,每个数字“属于”一个位置。当我去创建房间时,我会自动生成一个下拉菜单,允许我从现有位置中进行选择。但这些都是不直观的值...例如“project.Location:1”
我想用与 id 1 相对应的名称、城市和州列值替换此“project.Location:1”。这是一个修改起来容易吗?我认为需要完成一些简单的映射...
提前致谢!
I'm creating a web application with grails, and I'm working on the CRUD prototype using Scaffold. Out of the box, the scaffold will use the unique id (which makes sense) for foreign key values, and I'm wondering if I can easily replace the unique id with a readable value (such as a combination of two values from said table).
For example:
I have Location and RoomNumber domains that represent a Hotel location and room number. Each number therefore "belongs-to" a location. When I go to create a room, I have a drop-down auto-generated that allows me to pick from existing locations. These are unintuitive values though... such as "project.Location : 1"
I'd like to replace this "project.Location : 1" with the name, city, and state column values that correspond to id 1. Is this an easy thing to modify? I'd think there's some simple mapping that needs to be done...
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明解决方案非常简单...只需在相应的 Domain 类中实现 toString 方法即可。从 Grails 邮件列表收到此答案。
Turns out the solution is really simple... just need to implement the toString method in the corresponding Domain class. Received this answer from the Grails mailing list.