【问题标题】:Play Framework route not working though defined correctlyPlay Framework 路由虽然定义正确但无法正常工作
【发布时间】:2013-02-13 00:35:22
【问题描述】:

我在 Play 的路由中定义了这个简单的路由:

POST /test/post/$id<[0-9]+>  controllers.Test.post(id: Long)  

这是Test.post方法的代码:

public static Result post(long id)
{
    return ok("working");
}

同一控制器中的另一条路由POST /test controllers.Test.index() 工作正常。但是,每当我访问http://localhost:9000/test/post/3 时,我会立即在 Firefox 中收到“连接重置”错误,而在 google chrome 中我会收到“空响应”错误。所有其他路线都正常工作。

我做错了什么?

【问题讨论】:

  • 只是为了排除您错过明显情况的极不可能的情况:“每当我访问 http://localhost:9000/test/post/3”时,您的意思是通过 POST 请求,而不是通过在浏览器中输入地址? (因为您的路线看起来不错...无论如何,如果您确实通过GET 访问它,您应该会收到一条找不到路线的错误消息...)
  • 只是一个小测试:在您的操作中使用Long 而不是long
  • @nico_ekito 很好,就是这样。如果您愿意,请发布答案,我会接受。

标签: java playframework playframework-2.0


【解决方案1】:

在 Action 中使用 Long 对象而不是 long 原生类型:

public static Result post(Long id)
{
    return ok("working");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2014-12-05
    • 2018-01-17
    • 2017-10-15
    相关资源
    最近更新 更多