编译应用程序时收到错误消息。
我的路线文件如下所示:
# Routes
# This file defines all application routes (Higher priority routes first)
# Home page
GET / Application.index
GET /listing/create Application.createAuctionItem
POST /listing/create Application.doCreateItem
GET /listing/show Application.show
GET /search Application.search
GET /rss/recent Application.recentlyAdded(format:'rss')
GET /recent Application.recentlyAdded
GET /signup Authenticate.register
POST /signup Authenticate.doRegister
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Catch all
* /{controller}/{action} {controller}.{action}
我的应用程序(Java)如下所示:
package controllers;
import play.mvc.*;
import models.*;
import java.util.List;
import play.data.validation.*;
import static play.modules.pdf.PDF.*;
public class Application extends Controller {
public static void recentlyAdded() {
List<AuctionItem> recentlyAdded = AuctionItem.recentlyAdded(50);
render(recentlyAdded);
}
public static void showPDF(Long id) {
AuctionItem item = AuctionItem.findById(id);
item.viewCount++;
item.save();
renderPDF(item);
}
public static void showImage(Long id) {
AuctionItem item = AuctionItem.findById(id);
renderBinary(item.photo.get());
}
public static void search(String search, Integer page) {
validation.required(search).message("You must enter something to search for");
if (validation.hasErrors()) {
render();
}
if (page == null) page = 1;
SearchResults results = AuctionItem.search(search, page);
render(results, page, search);
}
public static void show(Long id) {
AuctionItem item = AuctionItem.findById(id);
item.viewCount++;
item.save();
render(item);
}
public static void doCreateItem(@Valid AuctionItem item) {
// if there are errors, redisplay the auction form
if (validation.hasErrors()) {
params.flash();
validation.keep();
createAuctionItem();
}
// set the user based on the logged in user
item.createdBy = Authenticate.getLoggedInUser();
// if no errors, save the auction item and redirect to the show page
item.save();
show(item.id);
}
public static void createAuctionItem() {
if (session.get("user") == null) {
Authenticate.login();
}
render();
}
public static void index() {
List<AuctionItem> mostPopular = AuctionItem.getMostPopular(5);
List<AuctionItem> endingSoon = AuctionItem.getEndingSoon(5);
render(mostPopular, endingSoon);
}
}
编译代码时出现以下错误:
[error] D:\Paly SampleApps\Chapter4\conf\routes:6: Compilation
error[Controller method call expected]
[error] GET /listing/create Application.createAuctio
nItem
我做错了什么?
答案 0 :(得分:1)
此外,您必须使用“ controllers ”命名空间,如此
GET /listing/show controllers.Application.show
答案 1 :(得分:0)
您的createAuctionItem
方法必须返回Result
而不是void
比照http://www.playframework.com/documentation/2.1.1/JavaActions