Spring Roo 不生成 CRUD
在 Spring Roo 中,我使用了本教程使用我的自定义 xsd 生成对象。
之后我使用命令controller all ~.web,生成了控制器,但没有CRUD功能。
如果我在 Roo 控制器中生成具有 CRUD 功能的手动对象。知道问题出在哪里吗?
就我而言,架构文件 xsd 对于 REST 数据交换很重要。
In Spring Roo I used this tutorial with my custom xsd to generate objects.
After that I used command controller all ~.web, controller is generated but without CRUD functions.
If I make manual objects in Roo controller with CRUD functions is generated. Any idea what is the problem?
Schema file xsd is in my case important for REST data exchange.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所指的教程确实解释了如何基于提供的 xml 架构创建 Java(域)模型,但 controller all ~.web 命令当前(版本 1.1.0)仅创建实际 Roo(数据库)实体的控制器和相应的 CRUD 功能。由于生成的 Java 类未标记为 Roo 实体,因此控制器命令不会创建您期望的 CRUD 命令,正如您所说,它将对手动创建的实体执行此操作,因为这些实体被标记为 Roo 实体(请参阅 @RooEntity对这些的注释)。
正如教程中还指出的,当您使用 Spring Roo jaxb 插件时,您将需要手动更新控制器和视图 (*.jspx) 文件以实现 CRUD 功能。我知道,通过检查论坛和 Jira 问题,目前有一些关于让 Spring Roo 为普通(非实体)bean 创建基本 CRUD 功能的想法(请参阅问题 ROO-344 及其相关的 ROO-277 问题),但这些目前只是想法,很可能不会在不久的将来实现。因此,当使用 XML 模式作为 Spring Roo 域模型的基础时,您仍然需要进行大量手动编码才能拥有基本的 CRUD 应用程序,而不是使用数据库作为生成域模型的基础,因为它基本上是在 Roo shell 中执行几个命令,然后就完成了。
如果您的 XML 架构只是域模型的定义,并且您确实希望应用程序将数据存储在数据库中并从数据库中检索数据,而不是调用 REST Web 服务来检索和存储更改,那么您可以尝试使用我使用 jaxb 插件来生成模型,然后注释生成的类,但由于我之前自己没有这样做过,所以我不确定这是否有效,但可能值得尝试。
The tutorial you're referring to indeed explains how you can create a Java (domain) model based on a provided xml Schema, but the controller all ~.web command currently (version 1.1.0) only creates controllers and corresponding CRUD functions for actual Roo (database) entities. As the generated Java classes are not marked as Roo entities, the controller command will not create the by you expected CRUD commands, which it, as you stated, will do for manually created entities as these are marked as Roo entities (see the @RooEntity annotation on these).
As the tutorial also states, you will need to manually update your controller and view (*.jspx) files to implement the CRUD functionality when you use the Spring Roo jaxb addon. I know, from checking the forum and Jira issues, that there are currently some ideas on also having Spring Roo create basic CRUD functionality for normal (none-entity) beans (see issue ROO-344 and it's related ROO-277 issue), but these are currently only ideas and most likely won't be implemented within the near future. So, when using a XML schema as base for your Spring Roo domain model, you'll still need to do quite a bit of manual coding to have a basic CRUD application, as opposed to using a database as your base for generating your domain model, as it then basically is executing a couple of commands in the Roo shell and you're done.
If your XML schema is but a definition of your domain model and you actually do want your data to be stored in and retrieved from the database by your application, as oposed to call a REST webservice for retrieving and storing changes, you might try to use the jaxb addon to generate the model and then annotate the generated classes, but as I haven't done that myself before, I'm not sure if that will work, but it might be worth trying.
Spring Roo 在 .java 源文件旁边生成 AspectJ (.aj) 文件。因此,您不会在源文件中看到这些方法。它们位于 .aj 文件中,但在编译后出现在生成的 .class 文件中。
Spring Roo generates AspectJ (.aj) files next to the .java source files. So, you won't see the methods in your source files. They are in the .aj files but are present after compile in the generated .class files.