我是 Play 框架的新手。我尝试按照示例编译我的游戏框架项目。当我编译示例时,它工作正常,并且在目标中将 .scala.html 视图编译为 .class。我添加了一个新视图,但它没有编译到目标中。任何建议如何解决这个问题?我尝试使用命令行编译激活器,清理并重新构建项目,单独构建 .scala.html,但没有任何尝试奏效。如何在 Play 2.4 中添加新视图并编译它?
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)