neo4j图数据库中创建关系的时候动态修改@RelationshipEntity(type = “xxx“)的关系名称

本文介绍如何在Neo4j图数据库中使用Java动态修改@RelationshipEntity的type属性,从而在创建关系时实现关系名称的动态变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本方法是通过反射去获取类上注解的value值并修改
@Data
@NoArgsConstructor
@RelationshipEntity(type = "属于")
public class BelongToRelation extends AbstractRelation<CIType, CIType>{
}
 public Class<BelongToRelation> updateAnnotationValue(String str) throws IllegalAccessException, NoSuchFieldException {
        Class<BelongToRelation> belongToRelationClass = BelongToRelation.class;

        RelationshipEntity annotation = belongToRelationClass.getAnnotation(RelationshipEntity.class);
        String type = annotation.type();

        System.out.println(type);
        //获取这个代理实例所持有的 InvocationHandler
        InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
        // 获取 AnnotationInvocationHandler 的 memberValues 字段
        Field declaredField = invocationHandler.getClass().getDeclaredField("memberValues");
        // 因为这个字段事 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值