[英]How to bind Enum to routes static parameter
How do I bind a enum from my Model to a static parameter in my routes definition? 如何将模型中的枚举绑定到路径定义中的静态参数?
Example (made up): 示例(组成):
Model: 模型:
class User (..)
{
public static enum TYPES { Default, Admin, Editor, Visitor }
}
Controller: 控制器:
class Users (..)
{
public static void create(long parentUserId, User.TYPES type)
{
(..)
}
}
Routes: 路线:
GET /user/{parentUserId}/create/editor Users.create(type:User.TYPES.Editor)
View template: 查看模板:
<a href="@{Users.create(user.id, 'Editor')}">create editor</a>
or 要么
<a href="@{Users.create(user.id, User.TYPES.Editor)}">create editor</a>
Both don't work. 两者都不起作用。 How should I set this up?
我该如何设置?
EDIT: I've tested this with working environment. 编辑:我用工作环境测试了这个。
The following works: 以下作品:
Template: 模板:
<a href="@{Application.create(5, models.Game.GameType.Succession.name())}">create editor</a>
Route: 路线:
GET /user/{parentUserId}/create/{type}/editor Application.create
Controller: 控制器:
public static void create(long parentUserId, Game.GameType type)
{ ... }
The route with a predefined parameter doesn't work: 具有预定义参数的路由不起作用:
GET /user/{parentUserId}/editor Application.create(type:models.Game.GameType.Succession.name())
It will always set type
to null
它总是将
type
设置为null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.