我使用" yo jhipster:entity"创建了3个实体(作者,书籍,图书馆)。命令,但在一个实体(库)中我有一个ManyToMany关系(预订),但导致" mappedBy引用一个未知的目标实体属性:com.tst.testdomain中的com.tst.testdomain.domain.Book.librarys。 docmain.Library.books"那么什么是删除库实体的干净方式。一个命令会像" yo jhipster:entitydelete"有用吗?
答案 0 :(得分:15)
我使用git scm。这不仅仅是需要删除的生成文件。 jHipster还会修改文件,以便保存文件但需要保留文件,而不是修改文件。
每次创建实体时,我都会单独提交,以便跟踪jHipster为每个实体所做的事情。
清除自上次提交以来的所有更改
git reset --hard
git clean -fd
如果我已经这样做但我还需要退出之前的提交,那么我就
git reset --hard HEAD~1
提交是git本地的,所以直到你推送这些提交才会共享它们。
答案 1 :(得分:9)
您应该删除以下内容:
rm -rf src/main/resources/config/liquibase/changelog/XXX_added_entity_YourEntity.xml
rm -rf src/main/java/com/radsphere/jeces/domain/YourEntity.java
rm -rf src/main/java/com/radsphere/jeces/repository/YourEntityRepository.java
rm -rf src/main/java/com/radsphere/jeces/web/rest/YourEntityResource.java
rm -rf src/main/webapp/scripts/app/entities/YourEntity/YourEntitys.html
rm -rf src/main/webapp/scripts/app/entities/YourEntity/YourEntity-detail.html
rm -rf src/main/webapp/scripts/app/entities/YourEntity/YourEntity.js
rm -rf src/main/webapp/scripts/app/entities/YourEntity/YourEntity.controller.js
rm -rf src/main/webapp/scripts/app/entities/YourEntity/YourEntity-detail.controller.js
rm -rf src/main/webapp/scripts/components/entities/YourEntity/YourEntity.service.js
rm -rf src/test/java/com/radsphere/jeces/web/rest/YourEntityResourceTest.java
rm -rf src/main/webapp/i18n/en/YourEntity.json
rm -rf src/main/webapp/i18n/fr/YourEntity.json
从config / liquibase / master.xml中删除引用:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307175923_added_entity_Company.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307180142_added_entity_UserTypeRecruiter.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307180338_added_entity_UserTypeCandidate.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307180448_added_entity_QuestionType.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307180612_added_entity_Question.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307180849_added_entity_Answer.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307181033_added_entity_CandidateAnswer.xml" relativeToChangelogFile="false"/>
<!--<include file="classpath:config/liquibase/changelog/20150307181249_added_entity_your_removed_entity.xml" relativeToChangelogFile="false"/>-->
<include file="classpath:config/liquibase/changelog/20150307182736_added_entity_ExamTemplate.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20150307182950_added_entity_Exam.xml" relativeToChangelogFile="false"/>
<!-- JHipster will add liquibase changelogs here -->
答案 2 :(得分:8)
我执行拉取请求以添加此功能: https://github.com/jhipster/generator-jhipster/pull/4369
要使用它,它很简单:
yo jhipster:entity Foo --remove
它删除了liquibase脚本,但在您需要处理已创建但尚未删除的表/列族之后。
如果您对此感兴趣,请投票或评论该问题: https://github.com/jhipster/generator-jhipster/issues/4372
答案 3 :(得分:6)
你是对的,删除命令会很有用。但是这个命令今天不存在。也许它会被添加。如果要删除实体,则必须手动执行。因此,删除实体的所有生成文件:domain,repository,rest,test,Angularjs controller&amp;服务,HTML视图,菜单链接,HTML视图
答案 4 :(得分:6)
您可以运行&#34; yo:jhipster实体&#34;再次覆盖其他一切。
Meme.-
答案 5 :(得分:4)
已编辑:为较新版本的jhipster 3.9.0添加了脚本
我的 delete-entity.sh jhipster Release 2.26.2脚本,基于@shacharsol的回答。
用法:./ delete-entity GROUP_ID ENTITY_NAME
GROUP_ID:com / subpackage /和/ so / on /(以'/'结尾)
ENTITY_NAME:firstLowercaseNameOfEntity
示例:./ delete -entity uz / javlon / transInfo
#!/usr/bin/env bash
echo "################";
if [ -z "$1" ];
then
printf "Required argument GROUP_ID is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME.\n";
exit 1;
else
GROUP_ID=$1;
echo "GROUP_ID is set to '$1'.";
fi
if [ -z "$2" ];
then
printf "Required argument ENTITY_NAME is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME .\n";
exit 1;
else
ENTITY_NAME=$2;
echo "ENTITY_NAME is set to '$2'.";
fi
echo;
rm -rf src/main/resources/config/liquibase/changelog/*_added_entity_${ENTITY_NAME^}.xml
rm -rf src/main/java/${GROUP_ID}domain/${ENTITY_NAME^}.java
rm -rf src/main/java/${GROUP_ID}repository/${ENTITY_NAME^}Repository.java
rm -rf src/main/java/${GROUP_ID}repository/search/${ENTITY_NAME^}SearchRepository.java
rm -rf src/main/java/${GROUP_ID}web/rest/${ENTITY_NAME^}Resource.java
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}s.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-dialog.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-dialog.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-delete-dialog.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-delete-dialog.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}/${ENTITY_NAME}.service.js
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}/${ENTITY_NAME}.search.service.js
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}
rm -rf src/test/java/${GROUP_ID}web/rest/${ENTITY_NAME^}ResourceIntTest.java
rm -rf src/test/gatling/simulations/${ENTITY_NAME^}GatlingTest.scala
rm -rf src/test/javascript/spec/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.controller.spec.js
rm -rf src/test/javascript/spec/app/entities/${ENTITY_NAME}
rm -rf src/main/webapp/i18n/en/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/ru/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/uz/${ENTITY_NAME}.json
rm -rf ./.jhipster/${ENTITY_NAME^}.json
echo;
echo "Deleting ${ENTITY_NAME^} is completed.";
echo "################";
我的另一个 delete-entity.sh jhipster Release 3.9.0脚本,基于@Tevfik Kiziloren的回答。
#!/usr/bin/env bash
echo;
if [ -z "$1" ];
then
printf "Required argument GROUP_ID is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME.\n";
exit 1;
else
GROUP_ID=$1;
echo "GROUP_ID is set to '$1'.";
fi
if [ -z "$2" ];
then
printf "Required argument ENTITY_NAME is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME .\n";
exit 1;
else
ENTITY_NAME=$2;
JAVA_ENTITY_NAME=`echo ${ENTITY_NAME:0:1} | tr '[a-z]' '[A-Z]'`${ENTITY_NAME:1}
echo "ENTITY_NAME is set to '$2'."
echo "Java entity name inferred as: '${JAVA_ENTITY_NAME}'.";
fi
JAVA_ENTITY_NAME=`echo ${ENTITY_NAME:0:1} | tr '[a-z]' '[A-Z]'`${ENTITY_NAME:1}
UNDERSCORED_FOLDER_NAME=`echo ${ENTITY_NAME} | sed -r 's/([a-z0-9])([A-Z])/\1-\L\2/g'`
echo ${UNDERSCORED_FOLDER_NAME};
QUESTION=$'You may want to keep definition file(.jhipster/'${JAVA_ENTITY_NAME}'.json) in case you want to regenerate entity in the future.\nDo you want to delete entity definition file also?'
while true; do
read -p "${QUESTION}" yn
case $yn in
[Yy]* ) rm -rf ./.jhipster/${ENTITY_NAME}.json; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo;
echo "Starting to delete files...";
rm -rf src/main/resources/config/liquibase/changelog/*_added_entity_${JAVA_ENTITY_NAME}.xml
rm -rf src/main/java/${GROUP_ID}domain/${JAVA_ENTITY_NAME}.java
rm -rf src/main/java/${GROUP_ID}repository/${JAVA_ENTITY_NAME}Repository.java
rm -rf src/main/java/${GROUP_ID}service/${JAVA_ENTITY_NAME}Service.java
rm -rf src/main/java/${GROUP_ID}service/impl/${JAVA_ENTITY_NAME}ServiceImpl.java
rm -rf src/main/java/${GROUP_ID}repository/search/${JAVA_ENTITY_NAME}SearchRepository.java
rm -rf src/main/java/${GROUP_ID}web/rest/${JAVA_ENTITY_NAME}Resource.java
rm -rf src/main/java/${GROUP_ID}web/rest/dto/${JAVA_ENTITY_NAME}DTO.java
rm -rf src/main/java/${GROUP_ID}web/rest/mapper/${JAVA_ENTITY_NAME}Mapper.java
rm -rf target/generated-sources/${GROUP_ID}web/rest/mapper/${JAVA_ENTITY_NAME}MapperImpl.java
rm -rf src/main/webapp/app/entities/${UNDERSCORED_FOLDER_NAME}/*
rm -rf src/test/java/${GROUP_ID}web/rest/${JAVA_ENTITY_NAME}ResourceIntTest.java
rm -rf src/test/gatling/simulations/${JAVA_ENTITY_NAME}GatlingTest.scala
rm -rf src/test/javascript/spec/app/entities/${UNDERSCORED_FOLDER_NAME}/*
rm -rf src/test/javascript/spec/app/entities/${UNDERSCORED_FOLDER_NAME}
rm -rf src/main/webapp/i18n/en/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/fr/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/ru/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/uz/${ENTITY_NAME}.json
echo "Deleting entity '${ENTITY_NAME}' is completed.";
echo;
echo "-----------------------------------------------------";
echo "Do not forget to manually correct these files also: ";
echo "-----------------------------------------------------";
echo " --> src/main/webapp/index.html"
echo " --> src/main/webapp/scripts/compopnents/navbar.html"
echo " --> src/main/webapp/i18n/**/global.json"
echo " --> src/main/resources/config/liquibase/master.xml (if you use liquibase)"
echo " --> src/main/resources/config/mongeez/master.xml (if you use mongodb)"
答案 6 :(得分:1)
在 jHipster 7.0.1 中,您应该删除以下文件:
jhipster/[EntityName].json
src/main/java/[base package]/domain/[EntityName].java
src/main/java/[base package]/repository/[EntityName]Repository.java
src/main/java/[base package]/repository/search/[EntityName]SearchRepository.java
src/main/java/[base package]/service/[EntityName]Service.java
src/main/java/[base package]/service/dto/[EntityName]DTO.java
src/main/java/[base package]/service/impl/[EntityName]ServiceImpl.java
src/main/java/[base package]/service/mapper/[EntityName]Mapper.java
src/main/java/[base package]/web/rest/[EntityName]Resource.java
src/main/resources/config/liquibase/changelog/*_added_entity_[EntityName].xml
src/main/resources/config/liquibase/changelog/*_added_entity_constraints_[EntityName].xml
src/main/resources/config/liquibase/fake-data/[entity_name].csv
src/test/java/[base package]/domain/[EntityName]Test.java
src/test/java/[base package]/repository/search/[EntityName]SearchRepositoryMockConfiguration.java
src/test/java/[base package]/service/dto/[EntityName]DTOTest.java
src/test/java/[base package]/service/mapper/[EntityName]MapperTest.java
src/test/java/[base package]/web/rest/[EntityName]ResourceIT.java
删除整个目录:
src/main/webapp/app/entities/[entity-name]
从以下文件中删除引用:
.yo-rc.json
src/main/java/[base package]/config/CacheConfiguration.java
src/main/resources/config/liquibase/master.xml
src/main/webapp/app/entities/entity-routing.module.ts
src/main/webapp/app/layouts/navbar/navbar.component.html
src/main/webapp/i18n/en/global.json
src/main/webapp/i18n/pt-br/global.json
删除数据库并让应用程序在启动时再次生成它。 如果您无法删除数据库,您需要创建一个更改日志来删除过时的表,而不是删除 liquibase 文件。
显然,根据您生成项目的方式,您的文件可能更少(或者可能更多)。
答案 7 :(得分:0)
我对SparX和Meme的答案做了一些补充。
我更新了SparX的bash脚本(delete-entity.sh),询问是否删除实体定义文件。此外,“$ {ENTITY_NAME ^}”语法(用于将实体名称的第一个字母转换为大写)不会在较旧的bash版本(例如3.2)中运行。
更新后的bash脚本如下所示。只需将此脚本放在 pom.xml 所在的文件夹中即可。
示例用例:如果您的项目的groupId “com.example”,并且您要删除名为“city”的实体 ,下面给出了一个示例命令:
./ delete-entity.sh com / example / city
#!/usr/bin/env bash
echo;
if [ -z "$1" ];
then
printf "Required argument GROUP_ID is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME.\n";
exit 1;
else
GROUP_ID=$1;
echo "GROUP_ID is set to '$1'.";
fi
if [ -z "$2" ];
then
printf "Required argument ENTITY_NAME is not set. \nUsage: ./delete-entity.sh GROUP_ID ENTITY_NAME .\n";
exit 1;
else
ENTITY_NAME=$2;
JAVA_ENTITY_NAME=`echo ${ENTITY_NAME:0:1} | tr '[a-z]' '[A-Z]'`${ENTITY_NAME:1}
echo "ENTITY_NAME is set to '$2'."
echo "Java entity name inferred as: '${JAVA_ENTITY_NAME}'.";
fi
JAVA_ENTITY_NAME=`echo ${ENTITY_NAME:0:1} | tr '[a-z]' '[A-Z]'`${ENTITY_NAME:1}
QUESTION=$'You may want to keep definition file(.jhipster/${JAVA_ENTITY_NAME}.json) in case you want to regenerate entity in the future.\nDo you want to delete entity definition file also?'
while true; do
read -p "${QUESTION}" yn
case $yn in
[Yy]* ) rm -rf ./.jhipster/${ENTITY_NAME}.json; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo;
echo "Starting to delete files...";
rm -rf src/main/resources/config/liquibase/changelog/*_added_entity_${JAVA_ENTITY_NAME}.xml
rm -rf src/main/java/${GROUP_ID}domain/${JAVA_ENTITY_NAME}.java
rm -rf src/main/java/${GROUP_ID}repository/${JAVA_ENTITY_NAME}Repository.java
rm -rf src/main/java/${GROUP_ID}service/${JAVA_ENTITY_NAME}Service.java
rm -rf src/main/java/${GROUP_ID}service/impl/${JAVA_ENTITY_NAME}ServiceImpl.java
rm -rf src/main/java/${GROUP_ID}repository/search/${JAVA_ENTITY_NAME}SearchRepository.java
rm -rf src/main/java/${GROUP_ID}web/rest/${JAVA_ENTITY_NAME}Resource.java
rm -rf src/main/java/${GROUP_ID}web/rest/dto/${JAVA_ENTITY_NAME}DTO.java
rm -rf src/main/java/${GROUP_ID}web/rest/mapper/${JAVA_ENTITY_NAME}Mapper.java
rm -rf target/generated-sources/${GROUP_ID}web/rest/mapper/${JAVA_ENTITY_NAME}MapperImpl.java
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}s.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-dialog.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-dialog.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-delete-dialog.html
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-delete-dialog.controller.js
rm -rf src/main/webapp/scripts/app/entities/${ENTITY_NAME}
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}/${ENTITY_NAME}.service.js
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}/${ENTITY_NAME}.search.service.js
rm -rf src/main/webapp/scripts/components/entities/${ENTITY_NAME}
rm -rf src/test/java/${GROUP_ID}web/rest/${ENTITY_NAME}ResourceIntTest.java
rm -rf src/test/gatling/simulations/${ENTITY_NAME}GatlingTest.scala
rm -rf src/test/javascript/spec/app/entities/${ENTITY_NAME}/${ENTITY_NAME}-detail.controller.spec.js
rm -rf src/test/javascript/spec/app/entities/${ENTITY_NAME}
rm -rf src/main/webapp/i18n/en/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/fr/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/ru/${ENTITY_NAME}.json
rm -rf src/main/webapp/i18n/uz/${ENTITY_NAME}.json
echo "Deleting entity '${ENTITY_NAME}' is completed.";
echo;
echo "-----------------------------------------------------";
echo "Do not forget to manually correct these files also: ";
echo "-----------------------------------------------------";
echo " --> src/main/webapp/index.html"
echo " --> src/main/webapp/scripts/compopnents/navbar.html"
echo " --> src/main/webapp/i18n/**/global.json"
echo " --> src/main/resources/config/liquibase/master.xml (if you use liquibase)"
echo " --> src/main/resources/config/mongeez/master.xml (if you use mongodb)"