简体   繁体   English

播放框架-具有Class参数的路由中的呼叫控制器

[英]Play framework - call controller in routes with Class parameter

I want to create controller method and parametrize it with Class parameter to call it in routes: 我想创建控制器方法并使用Class参数对其进行参数化,以在路由中调用它:

GET     /api/res1           controllers.GenericController.index(clazz:Class = Res1.class)
GET     /api/res2           controllers.GenericController.index(clazz:Class = Res2.class)

and during compilation play shouts: 在编译过程中大喊:

[error] /home/../workspace/repo/prototype/conf/routes:26: identifier expected but 'class' found.
[error] /home/../workspace/repo/prototype/conf/routes:26: ')' expected but '}' found.

why '}' ? 为什么是'}'? and how to make my idea work? 以及如何使我的想法可行?

Try changing to this: 尝试更改为此:

/api/res1   controllers.GenericController.index(clazz: Class[_] = classOf[full.package.name.Res1])

Works just fine for me. 对我来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM