我是Play框架的新手。我试图在示例后编译我的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)
答案 0 :(得分:0)
如果服务器在您编码时没有运行,则无法编译更改。您可以通过打开连续编译功能来解决此问题,每次将更改写入文件系统时都会进行编译。
要做到这一点:
~compile
~
表示应立即编译更改。
您可以对服务器执行类似操作。通过使用~run
,将在文件系统更改时立即编译更改,并且在浏览器刷新之前不会延迟更改。