Grails 3 Restful 调用自定义 API 不工作
Grails 3 Restful call to custom API not working
尝试对特殊的 oracle pl/sql 验证包进行自定义调用,该验证包执行超出自定义域级别验证器的操作,但未触发 "firemyvalidations"。你可以看到我尝试过的一些东西被注释掉了。谁能发现我的问题?我正在使用带有 angularjs rest 配置文件的 grails 3.2.6。
urlmappings.groovy
package fytrnlt
class UrlMappings {
static mappings = {
delete "/$controller/$id(.$format)?"(action:"delete")
get "/$controller(.$format)?"(action:"index")
get "/$controller/$id(.$format)?"(action:"show")
post "/$controller(.$format)?"(action:"save")
put "/$controller/$id(.$format)?"(action:"update")
patch "/$controller/$id(.$format)?"(action:"patch")
//"/fetchStvnatnData"(controller: 'FybkbraController', action: 'fetchStvnatn')
"/events"(resources:"event")
"/fytrnlts"(resources:"fytrnlt")
//"/fytrnlts"(resources:"fytrnlt"){"/fytrnlts/myvalidations" (controller: "FytrnltController", action: "myvalidations", method: "POST")}
// "/fytrnlts/myvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'POST')
"/firemyvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'GET')
"/spridens"(resources:"spriden")
// "/fybkbras"(resources:"fybkbra")
"/fybkbras"(resources:"fybkbra"){"/fetchStvnatnData" (controller: "FybkbraController", action: "fetchStvnatn", method: "GET")}
"/fytbanks"(resources:"fytbank")
"/fyrsigns"(resources:"fyrsign")
"/"(view: '/index')
"500"(view: '/error')
"404"(view: '/notFound')
}
}
FytrnltController.groovy
package fytrnlt
import grails.rest.*
import grails.converters.*
import fytrnlt.BannerService
class FytrnltController extends RestfulController {
//def bannerService
static responseFormats = ['json', 'xml']
FytrnltController() {
super(Fytrnlt)
}
def myvalidations(){
//def String mresult = bannerService.dataValidation()
def fytrnlt = Fytrnlt.get(4)
def CheckResult = fytrnlt.bannerService.documentValidation(fytrnlt.checkpayeepidm, fytrnlt.benefiaryname, fytrnlt.id, fytrnlt.userid, 1, fytrnlt.version, fytrnlt.actnum, fytrnlt.actnumintmdry, fytrnlt.swift, fytrnlt.createdate, null)
respond CheckResult, [excludes: ['class']]
/*
def fytrnlt = Fytrnlt.get(params.id)
if (fytrnlt.validate()) {
def CheckResult = fytrnlt.bannerService.documentValidation(fytrnlt.checkpayeepidm, fytrnlt.benefiaryname, fytrnlt.id, fytrnlt.userid, 1, fytrnlt.version, fytrnlt.actnum, fytrnlt.actnumintmdry, fytrnlt.swift, fytrnlt.createdate, null)
return CheckResult
} */
}
}
通过 Postman 访问端点returns 404 错误。
Grails 生成以下内容:
WARN --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/firemyvalidations] in DispatcherServlet with name 'grailsDispatcherServlet'
您不需要将 Controller 后缀添加到 URL 映射:
因此,您可以替换:
"/firemyvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'GET')
与:
"/firemyvalidations" (controller: 'fytrnlt', action: 'myvalidations', method: 'GET')
尝试对特殊的 oracle pl/sql 验证包进行自定义调用,该验证包执行超出自定义域级别验证器的操作,但未触发 "firemyvalidations"。你可以看到我尝试过的一些东西被注释掉了。谁能发现我的问题?我正在使用带有 angularjs rest 配置文件的 grails 3.2.6。
urlmappings.groovy
package fytrnlt
class UrlMappings {
static mappings = {
delete "/$controller/$id(.$format)?"(action:"delete")
get "/$controller(.$format)?"(action:"index")
get "/$controller/$id(.$format)?"(action:"show")
post "/$controller(.$format)?"(action:"save")
put "/$controller/$id(.$format)?"(action:"update")
patch "/$controller/$id(.$format)?"(action:"patch")
//"/fetchStvnatnData"(controller: 'FybkbraController', action: 'fetchStvnatn')
"/events"(resources:"event")
"/fytrnlts"(resources:"fytrnlt")
//"/fytrnlts"(resources:"fytrnlt"){"/fytrnlts/myvalidations" (controller: "FytrnltController", action: "myvalidations", method: "POST")}
// "/fytrnlts/myvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'POST')
"/firemyvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'GET')
"/spridens"(resources:"spriden")
// "/fybkbras"(resources:"fybkbra")
"/fybkbras"(resources:"fybkbra"){"/fetchStvnatnData" (controller: "FybkbraController", action: "fetchStvnatn", method: "GET")}
"/fytbanks"(resources:"fytbank")
"/fyrsigns"(resources:"fyrsign")
"/"(view: '/index')
"500"(view: '/error')
"404"(view: '/notFound')
}
}
FytrnltController.groovy
package fytrnlt
import grails.rest.*
import grails.converters.*
import fytrnlt.BannerService
class FytrnltController extends RestfulController {
//def bannerService
static responseFormats = ['json', 'xml']
FytrnltController() {
super(Fytrnlt)
}
def myvalidations(){
//def String mresult = bannerService.dataValidation()
def fytrnlt = Fytrnlt.get(4)
def CheckResult = fytrnlt.bannerService.documentValidation(fytrnlt.checkpayeepidm, fytrnlt.benefiaryname, fytrnlt.id, fytrnlt.userid, 1, fytrnlt.version, fytrnlt.actnum, fytrnlt.actnumintmdry, fytrnlt.swift, fytrnlt.createdate, null)
respond CheckResult, [excludes: ['class']]
/*
def fytrnlt = Fytrnlt.get(params.id)
if (fytrnlt.validate()) {
def CheckResult = fytrnlt.bannerService.documentValidation(fytrnlt.checkpayeepidm, fytrnlt.benefiaryname, fytrnlt.id, fytrnlt.userid, 1, fytrnlt.version, fytrnlt.actnum, fytrnlt.actnumintmdry, fytrnlt.swift, fytrnlt.createdate, null)
return CheckResult
} */
}
}
通过 Postman 访问端点returns 404 错误。
Grails 生成以下内容:
WARN --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/firemyvalidations] in DispatcherServlet with name 'grailsDispatcherServlet'
您不需要将 Controller 后缀添加到 URL 映射:
因此,您可以替换:
"/firemyvalidations" (controller: 'FytrnltController', action: 'myvalidations', method: 'GET')
与:
"/firemyvalidations" (controller: 'fytrnlt', action: 'myvalidations', method: 'GET')