JHipster在线生成项目缺失Model.jdl及权限枚举扩展咨询
Let’s tackle your questions one by one:
1. Why is src/model/Model.jdl missing when using the online generator?
The Eclipse JHipster plugin generates and stores the JDL file locally as part of its workflow—it keeps the JDL tied directly to your project for easy updates later.
On the other hand, the online generator’s default workflow converts your configuration choices directly into project code without including the raw JDL file in the downloaded zip. But you can get the JDL file easily:
- Before generating the app, use the "Design your JDL" tab to build your model, then export the JDL (look for the export button)
- Or, after configuring your app in the online generator, check the "Advanced" section for an option to download the corresponding JDL file alongside the project zip.
2. JDL Code for User & Authority
Here’s a standard JDL snippet that defines the User and Authority entities with their typical relationship:
enum AuthorityName { ROLE_USER, ROLE_ADMIN } entity Authority { name AuthorityName required unique } entity User { login String required unique, password String required, firstName String, lastName String, email String required unique, activated Boolean required, langKey String, imageUrl String, activationKey String, resetKey String, resetDate Instant } relationship ManyToMany { User{authority(name)} to Authority{user(login)} } // Add JHipster's standard settings for core entities service Authority with serviceClass service User with serviceClass dto Authority with mapstruct dto User with mapstruct
3. Is authority.name an enum? How to add more values?
Yes, authority.name is almost always defined as an enum in JHipster projects (as shown in the JDL above)—this ensures role consistency across your app.
To add more enum values:
If you’re using JDL (recommended):
- Edit your JDL file’s
AuthorityNameenum to include new roles, e.g.:enum AuthorityName { ROLE_USER, ROLE_ADMIN, ROLE_MODERATOR, // New role ROLE_GUEST // New role } - Run the command
jhipster import-jdl your-model.jdlin your project root—this will update the enum class, database schema, and any related code automatically.
- Edit your JDL file’s
If you’ve already generated the project without JDL:
- Locate the
AuthorityNameenum class (usually insrc/main/java/[your-package]/domain/enumeration/AuthorityName.java) - Add your new enum values directly in the class, e.g.:
public enum AuthorityName { ROLE_USER, ROLE_ADMIN, ROLE_MODERATOR, ROLE_GUEST } - Don’t forget to update your database (if using JPA) to reflect the new allowed values—you can generate a Liquibase/Flyway migration script for this change.
- Locate the
内容的提问来源于stack exchange,提问作者Jeya Balaji

