【问题标题】:Controller method call expected when compiling a Play Framework application编译 Play Framework 应用程序时需要调用控制器方法
【发布时间】:2013-05-22 06:44:04
【问题描述】:

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

我的路线文件如下所示:

# 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

我做错了什么?

【问题讨论】:

    标签: java playframework playframework-2.1


    【解决方案1】:

    另外,你必须像这样使用“controllers”命名空间

    GET     /listing/show                           controllers.Application.show
    

    【讨论】:

      【解决方案2】:

      您的createAuctionItem 方法必须返回Result 而不是void

      参见。 http://www.playframework.com/documentation/2.1.1/JavaActions

      【讨论】:

        猜你喜欢
        • 2015-08-13
        • 1970-01-01
        • 2019-09-09
        • 2015-06-04
        • 2013-11-02
        • 1970-01-01
        • 2019-08-14
        • 2016-10-08
        • 1970-01-01
        相关资源
        最近更新 更多