gpt4 book ai didi

java - 编译 Play Framework 应用程序时需要调用 Controller 方法

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:06 25 4
gpt4 key购买 nike

我在编译应用程序时收到错误消息。

我的路线文件如下所示:

# 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

我做错了什么?

最佳答案

此外,您还必须使用“ Controller ”命名空间,如下所示

GET     /listing/show                           controllers.Application.show

关于java - 编译 Play Framework 应用程序时需要调用 Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16685112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com