我正在使用脚手架为 Grails 3 中的 Oracle 12c DB 创建一个简单的 CRUD,同时为具有显式整数 ID 列的简单表创建一个简单的 CRUD,如下所示:
class Config {
int id
String name
String type
String value
String description
int status
static constraints = {
/* constraints constraints constraints */
}
static mapping = {
sort 'name'
version false
id column: 'CONFIGID', name:'id', generator:'sequence', params:[sequence: 'CONFIG_SEQ']
}
}
一切正常,您可以通过 ListView 中自动生成的链接以及 config/<view>/<ID>
形式的显式 URL 来访问给定行的脚手架 View 。 ,一旦我有了一个带有像这样的复合键的表:
class AliasFrequencyDict implements Serializable{
String frequency
String unit
String description
String lang
static constraints = {
/* constraints constraints constraints */
}
static mapping = {
sort 'frequency'
version false
id composite: ['frequency', 'unit', 'lang']
}
}
...您无法再访问这些行(或者我不知道如何访问)。脚手架不再生成指向 ListView 中 View 的链接,并尝试通过类似 aliasFrequencyDict/show/0/D/PL
的 URL 访问它。 (这恰好是 /<view>/<frequency>/<unit>/<lang>
就像复合 id 定义中指定的那样)会导致 404。
使用复合 ID 时如何访问相关的显示、编辑等页面?
最佳答案
How do I access the relevant show, edit etc. pages when using a composite ID?
有很多方法可以做到这一点。例如,对于 show
,您可以有一个如下所示的 URL 映射...
"/aliasFreqDict/$freq/$unit/$language"(controller: 'aliasFreqDict', action: 'show')
然后有相应的 Controller Action ...
class AliasFreqDictController {
AliasFreqService aliasFreqService
def show(String freq, String unit, String language) {
// have a service method that looks up the instance by these properties...
respond aliasFreqService.find(freq, unit, language)
}
}
希望对您有所帮助。
关于java - 如何在 Grails 中使用组合键访问行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54745292/