简体   繁体   English

在Play Framework上生成管理区域(CRUD)

[英]Generate Admin area ( CRUD ) on Play Framework

I'm following the Official tutorial for creating a administration area. 我正在遵循创建管理区域的官方教程 I did the first step correctly but when i extend my controller class to CRUD i got an error (Crud not found on the project) + Access denied when I access to http://localhost:9000/admin/ . 我正确地做了第​​一步但是当我将我的控制器类扩展到CRUD时我得到了一个错误(在项目中找不到Crud)+当我访问http:// localhost:9000 / admin /Access denied访问。 This is what I did: 这就是我做的:

  1. Enable the CRUD module for the application In the /conf/application.conf file, enable the CRUD module by adding this line: 为应用程序启用CRUD模块在/conf/application.conf文件中,通过添加以下行来启用CRUD模块:

    module.crud=${play.path}/modules/crud

    Import default CRUD routes 导入默认的CRUD路由

  2. In the conf/routes file, import the default module routes by adding this line: 在conf / routes文件中,通过添加以下行来导入默认模块路由:

    * /admin module:crud

  3. Create the Users controller 创建用户控制器

     package controllers; public class Users extends CRUD { } 
  4. Restarted play & eclipse 重启播放和日食

Any suggestion to get the admin area work please ? 有任何建议让管理区域工作吗?

尝试再次运行此命令

play eclipsify myApp 

Thanks for the tip, play eclipsify made the trick but before, i had to resolve dependencies as they are now in the dependencies.yml file: 感谢提示,播放eclipsify成功了但之前,我必须解决依赖关系,因为它们现在位于dependencies.yml文件中:

# Application dependencies

require:
    - play
    - play -> crud

Just launch "play dependencies myApp" and then eclipsify. 只需启动“播放依赖项myApp”,然后启动eclipsify。 Reload your project in Eclipse and it works. 在Eclipse中重新加载项目并且它可以工作。

Tested in latest (1.2.3) 最新测试(1.2.3)

Fabien 法比恩

This could be caused by several issues. 这可能是由几个问题引起的。 Let me outline steps to validate your setup: 让我概述一下验证设置的步骤:

  1. Controller name must be plural (controllers/Users.java) 控制器名称必须是复数(controllers / Users.java)
  2. Make sure you have model (models/User.java) 确保你有模型(models / User.java)
  3. Controller must extend CRUD 控制器必须扩展CRUD
  4. run play dependencies 运行播放依赖项
  5. run play eclipsify and re-import project (just in case) run play eclipsify并重新导入项目(以防万一)
  6. Annotate model with @Entity 使用@Entity注释模型
  7. Routes for /admin must be before /{controller.action} ... / admin的路由必须在 /{controller.action} 之前 ...
  8. application.conf must contain following line: application.conf必须包含以下行:
     module.crud=${play.path}/modules/crud</li> 

Comments: 评论:

  • Used Play framework version 1.2.3 does not require to have crud in dependencies.yml 使用Play框架版本1.2.3不需要在dependencies.yml中使用crud

I don't understand your problem but there can be a problem with your route definitions. 我不明白您的问题,但您的路线定义可能存在问题。 Please check your conf/routes file 请检查您的conf / routes文件
the entry .* /admin module:crud seems a little bit strange to me 条目.* /admin module:crud对我来说有点奇怪
when you start your play! 当你开始游戏时! server are there any logging messages indicating wrong route definitions? 服务器是否有任何记录消息指示错误的路由定义? eg Invalid route definition : .* /admin module:crud 例如Invalid route definition : .* /admin module:crud
I think the definition should look something like this * /admin module:crud 我认为定义应该类似于* /admin module:crud

The solution for me was this: 我的解决方案是这样的:

The Controller objects must be plural (end in s )! Controller对象必须是复数(以s结尾)!

The controller's class name has to be the model class name with a final 's'. 控制器的类名必须是带有final's'的模型类名。

eg if you have User.java model object, the controller object extending CRUD must be User *s* .java 例如,如果您有User.java模型对象,则扩展CRUD的控制器对象必须是User * s * .java

I was running Play 1.2.3 on Windows 7 and this took me a while to figure out, hope it helps someone else! 我在Windows 7上运行Play 1.2.3,这花了我一段时间才弄明白,希望它可以帮助别人!

If you look at the tutorial, the route file is as follows 如果查看教程,路由文件如下所示

# Import CRUD routes
*      /admin              module:crud

You should also check that the CRUD module exists, by going to 您还应该检查CRUD模块是否存在

play/modules/crud/

If it does not exist, I would suggest downloading the latest version of Play. 如果它不存在,我建议下载最新版本的Play。

我不小心在model包而不是models下编写了我的实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM