URL 映射抛出 404 请求 GRAILS 未找到
URL mapping throws 404 not found on request GRAILS
我目前将 Grails 4 用于 RESTfull 应用程序。
具有以下控制器,一个自定义控制器,它会抛出 json 响应:
package nslbv_siu
import grails.rest.*
import grails.converters.*
class LoginController
{
static allowedMethods = [ login:'POST' ]
static responseFormats = [ 'json', 'xml' ]
static defaultAction = "login"
def login()
{
if( params.user == '' )
{
render "{ 'succes':false, 'error':'Ingrese su usuario.' }"
}
if( params.pass == '' )
{
render "{ 'success':false, 'error':'Ingrese su contraseña.' }"
}
def attempted_user = User.queryUserByUsernameAndActive( params.user, true )
if( attempted_user )
{
if ( attempted_user.pass == params.pass.md5() )
{
render "{ 'success':true, 'error':'', " +
"'user':'" + attempted_user.user + "', " +
"'mail':'" + attempted_user.dni + "', " +
"'apenom':'" + attempted_user.apenom + "', " +
"'profile_pic':'" + attempted_user.profile_pic + "' }"
}
else
{
render "{ 'success':false, 'error':'Usuario o Contraseña incorrectos' }"
}
}
else
{
render "{ 'success':false, 'error':'Usuario o Contraseña incorrectos' }"
}
}
User queryUserByUsernameAndActive(String username, Boolean active)
{
User.all.find
{
it.user == username && it.active == active
}
}
}
需要调用http://localhost:8080/login?user=myuser&pass=mypass
但是抛出 404 未找到,不知道为什么!我必须使用其他约定来发布我的路线吗?
我的映射:
package nslbv_siu
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")
"/"(controller: 'application', action:'index')
"500"(view: '/error')
"404"(view: '/notFound')
"/login"(controller: "LoginController", action: "login") -->does not seem to work
}
}
我不明白为什么它不起作用!我做错了什么吗?
grails url-mappings-report 抛出以下内容
动态映射
| * |错误:404 |查看:/notFound |
| * |错误:500 |查看:/错误|
控制器:登录控制器
| POST | /登录 |操作:登录 |
控制器:应用程序
| * | / |操作:索引 |
是:
"/login"(controller: "login", action: "login")
而不是
"/login"(controller: "LoginController", action: "login")
我目前将 Grails 4 用于 RESTfull 应用程序。 具有以下控制器,一个自定义控制器,它会抛出 json 响应:
package nslbv_siu
import grails.rest.*
import grails.converters.*
class LoginController
{
static allowedMethods = [ login:'POST' ]
static responseFormats = [ 'json', 'xml' ]
static defaultAction = "login"
def login()
{
if( params.user == '' )
{
render "{ 'succes':false, 'error':'Ingrese su usuario.' }"
}
if( params.pass == '' )
{
render "{ 'success':false, 'error':'Ingrese su contraseña.' }"
}
def attempted_user = User.queryUserByUsernameAndActive( params.user, true )
if( attempted_user )
{
if ( attempted_user.pass == params.pass.md5() )
{
render "{ 'success':true, 'error':'', " +
"'user':'" + attempted_user.user + "', " +
"'mail':'" + attempted_user.dni + "', " +
"'apenom':'" + attempted_user.apenom + "', " +
"'profile_pic':'" + attempted_user.profile_pic + "' }"
}
else
{
render "{ 'success':false, 'error':'Usuario o Contraseña incorrectos' }"
}
}
else
{
render "{ 'success':false, 'error':'Usuario o Contraseña incorrectos' }"
}
}
User queryUserByUsernameAndActive(String username, Boolean active)
{
User.all.find
{
it.user == username && it.active == active
}
}
}
需要调用http://localhost:8080/login?user=myuser&pass=mypass 但是抛出 404 未找到,不知道为什么!我必须使用其他约定来发布我的路线吗?
我的映射:
package nslbv_siu
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")
"/"(controller: 'application', action:'index')
"500"(view: '/error')
"404"(view: '/notFound')
"/login"(controller: "LoginController", action: "login") -->does not seem to work
}
}
我不明白为什么它不起作用!我做错了什么吗?
grails url-mappings-report 抛出以下内容
动态映射 | * |错误:404 |查看:/notFound | | * |错误:500 |查看:/错误|
控制器:登录控制器 | POST | /登录 |操作:登录 |
控制器:应用程序 | * | / |操作:索引 |
是:
"/login"(controller: "login", action: "login")
而不是
"/login"(controller: "LoginController", action: "login")