gpt4 book ai didi

java - PlayFramework 2.1.5/Java/Action 未找到

转载 作者:行者123 更新时间:2023-12-01 04:20:01 25 4
gpt4 key购买 nike

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index()

# Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)

网址:

http://localhost:9000/tasks/2/delete

错误:

Action not found

For request 'GET /tasks/2/delete'
These routes have been tried, in this order:

1 GET / controllers.Application.index()
2 GET /tasks controllers.Application.tasks()
3 POST /tasks controllers.Application.newTask()
4 POST /tasks/$id<[^/]+>/delete controllers.Application.deleteTask(id:Long)
5 GET /assets/$file<.+> controllers.Assets.at(path:String = "/public", file:String)

HTML 片段:

<form action="/tasks/2/delete" method="POST" >
<input type="submit" value="Delete">
</form>

我不明白为什么规则#4 不能适用。

我的错误在哪里?

最佳答案

我终于完成了自己的 POST 请求以添加缺少的 id:

@(tasks: List[Task], taskForm: Form[Task])

@import helper._

@main("Todo list") {
<h1>@tasks.size() task(s)</h1>
<ul>
@for(task <- tasks) {
<li>
@task.label
@form(routes.Application.deleteTask(task.id)) {
<input type="hidden" id="id" value="@task.id"><!-- *** added ***-->
<input type="submit" value="Delete">
}
</li>
}
</ul>

<h2>Add a new task</h2>
@form(routes.Application.newTask()) {
@inputText(taskForm("label"))
<input type="submit" value="Create">
}
}

生成的 HTML 为:

<form action="/tasks/1/delete" method="POST" >
<input type="hidden" id="id" value="1">
<input type="submit" value="Delete">
</form>

在 PlayFramework 2.1.5 之上执行的 PlayFramework 2.2.0 的 todolist 示例效果不佳...

关于java - PlayFramework 2.1.5/Java/Action 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19028237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com