How to modify existing entity generated with jhipster?

前端 未结 7 904
说谎
说谎 2020-12-04 12:30

I use jhipster generator to create a projet. I\'ve generated some entity manually following the information provided in jhipster documentation :

相关标签:
7条回答
  • 2020-12-04 12:40

    What I've done to modify jhipster entity like a Relationship to add new tables was:

    1. (save project before anything happens :p) yo jhipster:entity TableToEdit and Edit whatever you want.Who to editTableOrAdd
    2. Then add the new tables.(optional)
    3. I had then I just had to do change or remove all the tables of the DataBase, to generate the new fields and relations on the SQL part automatically.

    Note: If after this steps, it has any error, serverError or something I regenerate de entityregenerate Entity. Of course if you want to keep all your data this is not a good alternative.

    0 讨论(0)
  • 2020-12-04 12:41

    You can also modify existing entities interactively, e.g. using yo jhipster:entity Foo for entity Foo.

    This way, you can regenerate all entities and dialogs.

    If you are using a RDBMS and liquibase, you have to write the changelog file(s) and add it to the master.xml. What helps here is using mvn liquibase:diff or gradlew liquibaseDiff, which you can run against your existing DB. Though, I would recommend to write the changelog files manually.

    0 讨论(0)
  • 2020-12-04 12:49

    I have solution worked for jhipster 3.4.2, it is the result of me in 1 day, hope it helpful to you :)

    1. Run yo jhipster:entity entityName
    2. Modify entities (add, remove, ...), at the end, jhipster will give question to override file, *IMPORTANT NOTE: select NO for changelog .xml file and navbar.html file.
    3. Back to project and run mvn compile liquibase:diff
    4. Run your application
    5. DONE
    0 讨论(0)
  • 2020-12-04 12:54

    For jhipster 5.7.0 you can run the entity command again and it will ask if you want to modify it.

     % jhipster entity device                                 
    INFO! Using JHipster version installed locally in current project's node_modules
    INFO! Executing jhipster:entity device
    INFO! Options: from-cli: true
    
    Found the .jhipster/Device.json configuration file, entity can be automatically generated!
    
    
    The entity device is being updated.
    
    ? Do you want to update the entity? This will replace the existing files for this entity, all your custom code will be overwritten 
      Yes, re generate the entity 
    ❯ Yes, add more fields and relationships 
      Yes, remove fields and relationships 
      No, exit
    
    0 讨论(0)
  • 2020-12-04 12:54

    You can modify entity by tow ways.

    First(using jdl-studio):

    update .jh or .jdl file by following steps:

    1) export .jh file using jhipster export-jdl myApp-jdl.jh command to root folder of your project. Also you can export the .jh file to particular path using jhipster export-jdl myPath/myApp-jdl.jh

    2) here, you can edit your existing entities. You can also add new entities.

    3) Then save this myApp-jdl.jh file to root folder of your project and run jhipster import-jdl myApp-jdl.jh or you can store it anywhere on your system and just give path to import from! like, jhipster import-jdl myPath/myApp-jdl.jh

    Second(using JHipster CLI):

    as suggested on official documentation jhipster.tech/creating-an-entity/ you can update your entity with following steps:

    1) type same command jhipster entity <my_entity_name> that we use to create entity using CLI. Here <my_entity_name> would be the entity name that we want to modify.

    2) it'll give you different options like, re generate the entity, add more fields and relationships, remove fields and relationships etc..

    3) make modifications as per our requirement.

    NOTE: it will automatically remove the manual changes that you did on pre-built JHipster project!

    SOLUTION:

    1) commit the code before modifying or adding new entity.

    2) when it'll ask you to overwrite the changes to files, you can skip overwrite option as per your requirement. Just a suggestion is not to chage navbar html file.

    3) after that, you can open it to Intellij or Eclipse. And then you can modify other changed files by local history. In Intellij, local history will be in VCS menu.

    0 讨论(0)
  • 2020-12-04 12:59

    1) Edit the json file representing your entity (add/remove field, the syntax is pretty easy, check in the end of the file if is required any change to the general entity properties like 'fieldsContainOneToMany'...), you'll find it in:

    <jhipster_root_folder>/.jhipster/entityName.json
    

    2) Build the code.

    3) In the root of your project run the command:

    yo jhipster:entity entityName
    

    NOTE: this command by default overwrite all your manual changes. I recommend to do a commit on a VCS repository before to run this command to eventually revert any not required change.

    4) run

    mvn liquibase:diff
    
    0 讨论(0)
提交回复
热议问题