我是新來的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
不關心視圖,無論你的路線是錯誤的還是控制器。控制器未被調用。在需要時編譯視圖,因此首先嚐試解決此問題。 –