我使用“yo jhipster:entity”命令创建了 3 个实体(作者、书籍、图书馆),但在一个实体(图书馆)中,我有一个多对多关系(与书籍),但这导致“mappedBy 引用未知的目标实体属性:com” com.tst.testdomain.docmain.Library.books 中的.tst.testdomain.domain.Book.librarys”那么删除 Library 实体的干净方法是什么。像“yo jhipster:entitydelete”这样的命令有用吗?
我为此使用 git scm 。需要删除的不仅仅是生成的文件。 jHipster 还会修改文件,因此您需要保留文件但取消更改。
每次创建实体时,我都会进行单独的提交,这样我就可以跟踪 jHipster 对每个实体所做的操作。
清除自上次提交以来的所有更改
git reset --hard
git clean -fd
如果我已经这样做了,但我还需要取消之前的提交,那么我会这样做
git reset --hard HEAD~1
提交是 git 本地的,因此直到您推送这些提交后它们才会被共享。
我提出了一个拉取请求来添加此功能: https://github.com/jhipster/generator-jhipster/pull/4369
使用方法非常简单:
yo jhipster:entity Foo --remove
它删除了 liquibase 脚本,但在您需要处理已创建且尚未删除的表/列系列之后。
如果您对此感兴趣,请投票或评论该问题: https://github.com/jhipster/generator-jhipster/issues/4372
您应该删除以下内容:
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 -->
你是对的,删除命令会很有用。但今天这个命令已经不存在了。也许会添加。如果要删除实体,则必须手动执行。因此,删除为您的实体生成的所有文件:域、存储库、休息、测试、Angularjs 控制器和服务、HTML 视图、菜单中的链接、HTML 视图
很简单,您只需删除目录 .jhipster/entityName.json 上的实体即可。
您可以再次运行“yo:jhipster实体”并覆盖其他所有内容。
模因。-
编辑:为新版本的 jhipster 3.9.0 添加了脚本
我的 jhipster delete-entity.sh 脚本Release 2.26.2,基于@shacharsol 的答案。
用法:./delete-entity GROUP_ID ENTITY_NAME
GROUP_ID:com/subpackage/and/so/on/(以“/”结尾)
ENTITY_NAME:实体的第一个小写名称
示例:./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)"
在 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 文件。
显然,根据您生成项目的方式,您可能拥有更少的文件(或者可能更多的文件)。
我对 SparX 和 Meme 的答案做了一些补充。
我更新了SparX的bash脚本(delete-entity.sh)以询问是否删除实体定义文件。 此外, "${ENTITY_NAME^}" 语法(用于将实体名称的第一个字母转换为大写)不在较旧的 bash 版本(例如 3.2)中运行。
更新后的 bash 脚本如下。只需将此脚本放入您的 pom.xml 所在的文件夹中即可。
示例用例: 如果您的项目的 groupId “com.example” 并且您想删除名为 “city” 的实体,下面给出了示例命令:
./delete-entity.sh com/example/城市
#!/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)"
9年零11个月前提问,2年零9个月前修改。然而 jhipster 并没有提供任何删除功能。有这么难吗