我是新来的Play框架。我试图按照样例编译我的play framework项目。当我编译示例时,它工作正常,并且.scala.html视图在目标中编译为.class。我添加了一个新的视图,但没有编入目标。任何建议如何解决这个问题?我尝试使用命令行进行激活器编译,清理并重新构建项目,单独构建.scala.html,但没有一个尝试工作。如何在Play 2.4中添加新视图并编译它?编译问题新视图.scala.html到.class
package controllers;
import models.Client;
import models.Server;
import models.TestEvent;
import models.TestPlan;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;
import views.formData.testFormData;
public class Application extends Controller {
// Default path request
// public Result index() {return ok(index.render("Your new application is ready."));}
/* Index Route Page
* Returns the page where the form is filled with the arguments passed
* Or an empty form if the id is 0
*/
public static Result getIndex(long id) {
testFormData testData;
// Find the corresponding index result to return (depends on the id)
if(id == 0)
testData = new testFormData();
else
testData = models.TestEvent.makeTestFormData(id);
Form<testFormData> formData = Form.form(testFormData.class).fill(testData);
return ok(index.render(formData,
Client.getClientNameList(),
Server.getServerNameList(),
TestPlan.getTestPlanNameList()));
}
// Process a form submission
// Bind HTTP Post data to an instance of testFormData
// If errors are found, re-render the page displaying the error data
// If errors are not found, re-render the page displaying good data
public static Result postIndex() {
// Retrieve the formData
Form<testFormData> formData = Form.form(testFormData.class).bindFromRequest();
// The retrieved formData has errors
if(formData.hasErrors()) {
return badRequest(index.render(formData,
Client.getClientNameList(),
Server.getServerNameList(),
TestPlan.getTestPlanNameList()));
}
// The formData does not have errors
else {
// Convert the form data into a testEvent Instance
TestEvent testEvent = TestEvent.makeTestEventInstance(formData.get());
return ok(index.render(formData,
Client.getClientNameList(),
Server.getServerNameList(),
TestPlan.getTestPlanNameList()));
}
}
}
路线:
GET / controllers.Application.getIndex(id:Long ?= 0)
POST / controllers.Application.postIndex()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
您的服务器是否正在运行,并且您是否有控制器操作返回新创建的视图?当您尝试从Web浏览器调用控制器操作时,您会得到什么?这也需要更改routes.conf。 –
Web浏览器上的错误是“value getIndex不是controllers.Application的成员”:GET/controllers.Application.getIndex(id:Long?= 0)我配置了routes.conf以匹配来自应用程序的操作.java文件。但是这些观点并不在目标之中。 – TypeSource
不关心视图,无论你的路线是错误的还是控制器。控制器未被调用。在需要时编译视图,因此首先尝试解决此问题。 –