开发者

How to bind Enum to routes static parameter

开发者 https://www.devze.com 2023-03-23 11:52 出处:网络
How do I bind a enum from my Model to a static parameter in my routes definition? Example (made up): Model:

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.cre开发者_开发百科ate(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

0

精彩评论

暂无评论...
验证码 换一张
取 消