简体   繁体   English

从未调用过的操作方法

[英]Action method never invoked

I'm working on a java web application with play framework 1.2.4. 我正在使用Play框架1.2.4开发Java Web应用程序。 In my view, I try to invoke a method in the controller but it doesn't work. 在我看来,我尝试在控制器中调用一个方法,但是它不起作用。 Here is the view code : 这是查看代码:

%{ url='/'+lang+'/artists/item?.name?.asString()+'-'+item?.id?.asString(); }% 
<a href="${url}"></a>

So the url is something like localhost:9000/en/artists/artistName-artistId , for the action code : 因此,该网址类似于localhost:9000/en/artists/artistName-artistId之类的操作代码:

public static void artistView(String lang, String artistName, String artistId, String mode)  {
    //my code here
            }

the routes conf : 路线conf:

GET     /{<(fr)|(en)|(ar)>lang}/artists/{artistName}-{<[0-9]{32}>artistId}                                                      MyControllerName.artistView(mode:'overview')

With this, my action is never invoked. 这样,我的动作就永远不会被调用。 What did I do wrong ? 我做错了什么 ? Thanks in advance. 提前致谢。

First, I see your URL is wrong, it should be: 首先,我看到您的网址错误,应该是:

%{ url='/'+lang+'/artists/'+item?.name?.asString()+'-'+item?.id?.asString(); }% 

Anyway, I think you can fix it. 无论如何,我认为您可以修复它。

Second, I think you want your artistId is the number from 1 character to 32 characters, not exactly 32 characters. 其次,我想您希望artistId是从1个字符到32个字符的数字,而不是32个字符。

So, route.conf should be: 因此,route.conf应该是:

GET     /{<(fr)|(en)|(ar)>lang}/artists/{artistName}-{<[0-9]{,32}>artistId}                                                      MyControllerName.artistView(mode:'overview')

Please read more about Regular Expression if you want to know why? 如果您想知道为什么,请阅读更多有关正则表达式的信息。

Note: (mode:'overview') will be no effect. 注意:( (mode:'overview')无效。 If you want to set default, please do it in your controller like: 如果要设置默认值,请在控制器中进行设置,例如:

if (mode == null) mode = "overview";

Hope that help. 希望对您有所帮助。

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

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