当前位置: 首页 > news >正文

p2p网站制作价格指数基金排名前十名

p2p网站制作价格,指数基金排名前十名,普工招聘最新招聘信息,在线网站建设平台哪个好文章目录 前言实体工具使用 前言 上一篇中,我们的Cypher都用的是字符串,字符串拼接简单,但存在写错的风险,对于一些比较懒的开发者,甚至觉得之间写字符串还更自在快速,也确实,但如果在后期需要…

文章目录

  • 前言
  • 实体工具
  • 使用

前言

上一篇中,我们的Cypher都用的是字符串,字符串拼接简单,但存在写错的风险,对于一些比较懒的开发者,甚至觉得之间写字符串还更自在快速,也确实,但如果在后期需要修改,如更高字段名或者一些级联的变动,会导致维护难,所以,这里这里我们模仿Mybatis-Plus写一个实体字段工具之间替换哪些字符串,以提高项目可维护性。
如需要了解上篇,位置:SpringBoot该怎么使用Neo4j

实体工具

我们以这篇的工具为基础进行下面的开发:Lambda表达式提取字段名-CSDN博客

然后我们再增加对于与Neo4j的实体工具:

  1. 实体缓存对象信息,保存实体必要信息

    public class EntityCache {private String className;private List<String> labels;private Map<String, String> fieldNameMap;public String getClassName() {return className;}public void setClassName(String className) {this.className = className;}public List<String> getLabels() {return labels;}public void setLabels(List<String> labels) {this.labels = labels;}public Map<String, String> getFieldNameMap() {return fieldNameMap;}public void setFieldNameMap(Map<String, String> fieldNameMap) {this.fieldNameMap = fieldNameMap;}
    }
  2. 解析工具,也就是反射解析

    public class EntityUtil {/*** 实体缓存*/private static final Map<String, EntityCache> ENTITY_MAP = new ConcurrentHashMap<>();public static void main(String[] args) {Job job = new Job();String column = column(Job::getName);System.out.println(column);System.out.println(label(Job.class));}/*** 从lambda转换出字段名*/public static <T, R> String column(CusFunction<T, R> column) {SerializedLambda resolve = LambdaUtils.resolve(column);return getColumn(LambdaUtils.getClass(resolve), LambdaUtils.getMethodName(resolve) , true);}/*** 从实体class解析出标签*/public static <T> String label(Class<T> clazz) {EntityCache info = ENTITY_MAP.putIfAbsent(clazz.getTypeName(), resolve(clazz));return info.getLabels().get(0);}/*** 根据类型和方法名解析字段名* @param aClass 类型* @param methodName 方法名* @param dbField 是否数据库字段* @return 字段名*/private static String getColumn(Class<?> aClass, String methodName, boolean dbField) {String fieldName = PropertyNamer.methodToProperty(methodName);if (!dbField) {return fieldName;}EntityCache info = resolve(aClass);if (!StringUtils.hasLength(fieldName)) {throw new RuntimeException(String.format("找不到实体对应的字段-[%s.%s]", aClass.getTypeName(), methodName));}Map<String, String> map = info.getFieldNameMap();return map.get(fieldName);}/*** 解析实体* @param clazz 类型* @return 实体缓存对象*/public static <T> EntityCache resolve(Class<T> clazz) {String typeName = clazz.getTypeName();EntityCache info = ENTITY_MAP.get(typeName);if (info != null) {return info;}Field[] declaredFields = clazz.getDeclaredFields();Map<String, String> fieldNameMap = new HashMap<>();for (Field declaredField : declaredFields) {declaredField.setAccessible(true);String fieldName = declaredField.getName();String dbFieldName = fieldName;Property property = declaredField.getAnnotation(Property.class);if (property != null) {if (StringUtils.hasLength(property.name())) {dbFieldName = property.name();}if (StringUtils.hasLength(property.value())) {dbFieldName = property.value();}}fieldNameMap.put(fieldName, dbFieldName);}List<String> labelList = resolveLabel(clazz);info = new EntityCache();info.setLabels(labelList);info.setClassName(typeName);info.setFieldNameMap(fieldNameMap);ENTITY_MAP.put(typeName, info);return info;}/*** 解析标签* @param clazz 类型* @return 标签列表*/private static <T> List<String> resolveLabel(Class<T> clazz) {Node node = clazz.getAnnotation(Node.class);if (node == null) {throw new RuntimeException("非数据库实体对象实体!");}String[] value = node.value();String[] labels = node.labels();List<String> result = new ArrayList<>();result.addAll(Arrays.asList(value));result.addAll(Arrays.asList(labels));if (result.isEmpty()) {result.add(clazz.getSimpleName());}return result;}
    }
  3. 测试:

        @Testpublic void testEntity() {String column = EntityUtil.column(Job::getName);EntityUtil.label(Job.class);String column1 = EntityUtil.column(Job::getJobName);System.out.println(column +"  " + column1);}
    

使用

实际开发中,就可以将字符串进行替换,如下面:

查询标签Jobname='liry',并通过id顺序排序,取第一个的cypher构建

// match(a:Job) where a.name='liry' return a order by a.id  limit 1Node temp = Cypher.node("Job").named("a");
ResultStatement statement = Cypher.match(temp).where(temp.property("name").isEqualTo(Cypher.anonParameter(job.getName()))).returning(temp.getRequiredSymbolicName()).orderBy(temp.property("id")).limit(1).build();

进行替换

// match(a:Job) where a.name='liry' return a order by a.id  limit 1// 字符串 Job  -> EntityUtil.label(Job.class)
// 字符串 name -> EntityUtil.column(Job::getName)
// 字符串 id -> EntityUtil.column(Job::getId)
Node temp = Cypher.node(EntityUtil.label(Job.class)).named("a");
ResultStatement statement = Cypher.match(temp).where(temp.property(EntityUtil.column(Job::getName)).isEqualTo(Cypher.anonParameter(job.getName()))).returning(temp.getRequiredSymbolicName()).orderBy(temp.property(EntityUtil.column(Job::getId))).limit(1).build();

创建一个节点:

create (a:Job{name:'liry',jobName:'liry-job'}) return a;          

可以看到调试中构建的Cypher是正确的。

image-20241204181636501


文章转载自:
http://dinncolawbreaking.bpmz.cn
http://dinncocavitate.bpmz.cn
http://dinncodredge.bpmz.cn
http://dinncopoilu.bpmz.cn
http://dinncophotomultiplier.bpmz.cn
http://dinncoseduction.bpmz.cn
http://dinncohypercorrection.bpmz.cn
http://dinncodiscreditably.bpmz.cn
http://dinncofloccillation.bpmz.cn
http://dinncoescapist.bpmz.cn
http://dinncobeau.bpmz.cn
http://dinncopaprika.bpmz.cn
http://dinnconerving.bpmz.cn
http://dinncohemigroup.bpmz.cn
http://dinncorafter.bpmz.cn
http://dinncopiosity.bpmz.cn
http://dinncorewrite.bpmz.cn
http://dinncoclaustrophobe.bpmz.cn
http://dinncopassive.bpmz.cn
http://dinncosubschema.bpmz.cn
http://dinncoadjutantship.bpmz.cn
http://dinncohaffit.bpmz.cn
http://dinncoseasick.bpmz.cn
http://dinncohousebody.bpmz.cn
http://dinncococcolith.bpmz.cn
http://dinncoalden.bpmz.cn
http://dinncogyplure.bpmz.cn
http://dinncocytophotometer.bpmz.cn
http://dinncopursuance.bpmz.cn
http://dinncoradiotracer.bpmz.cn
http://dinncotonicity.bpmz.cn
http://dinncorootlet.bpmz.cn
http://dinncofranchiser.bpmz.cn
http://dinncopilus.bpmz.cn
http://dinncoradiolocation.bpmz.cn
http://dinncoodor.bpmz.cn
http://dinncoallograph.bpmz.cn
http://dinncosemiaxis.bpmz.cn
http://dinncoequably.bpmz.cn
http://dinncosalpicon.bpmz.cn
http://dinncoeditioprinceps.bpmz.cn
http://dinncocoadjutrix.bpmz.cn
http://dinncoplanner.bpmz.cn
http://dinncoararoba.bpmz.cn
http://dinncomadonna.bpmz.cn
http://dinncoganglionate.bpmz.cn
http://dinncoforemilk.bpmz.cn
http://dinncotaiga.bpmz.cn
http://dinncobridgework.bpmz.cn
http://dinncorigorism.bpmz.cn
http://dinncoregalist.bpmz.cn
http://dinncotremolando.bpmz.cn
http://dinncochile.bpmz.cn
http://dinncozilch.bpmz.cn
http://dinncothornback.bpmz.cn
http://dinncolunchtime.bpmz.cn
http://dinncosirventes.bpmz.cn
http://dinncoescalate.bpmz.cn
http://dinncocognomen.bpmz.cn
http://dinncoepinephrine.bpmz.cn
http://dinncoeton.bpmz.cn
http://dinncocheezit.bpmz.cn
http://dinncosomnus.bpmz.cn
http://dinncounderabundant.bpmz.cn
http://dinncoperidental.bpmz.cn
http://dinncobitterbrush.bpmz.cn
http://dinncoscornfulness.bpmz.cn
http://dinncoingestion.bpmz.cn
http://dinncosuperrace.bpmz.cn
http://dinncoshlemiel.bpmz.cn
http://dinncopeignoir.bpmz.cn
http://dinncocommute.bpmz.cn
http://dinncosmother.bpmz.cn
http://dinncodishearten.bpmz.cn
http://dinncowinless.bpmz.cn
http://dinncolapdog.bpmz.cn
http://dinncocalypsonian.bpmz.cn
http://dinncocardiology.bpmz.cn
http://dinnconattier.bpmz.cn
http://dinncoclaimsman.bpmz.cn
http://dinncosock.bpmz.cn
http://dinncocriminalistics.bpmz.cn
http://dinncotransphasor.bpmz.cn
http://dinncohallux.bpmz.cn
http://dinncobeguine.bpmz.cn
http://dinncodyeline.bpmz.cn
http://dinncoabfarad.bpmz.cn
http://dinncoaposelenium.bpmz.cn
http://dinncohydroformate.bpmz.cn
http://dinncomillion.bpmz.cn
http://dinncoethnohistorian.bpmz.cn
http://dinncorounded.bpmz.cn
http://dinncoorangey.bpmz.cn
http://dinncoretailing.bpmz.cn
http://dinncocremate.bpmz.cn
http://dinncoureterolithotomy.bpmz.cn
http://dinncoafflux.bpmz.cn
http://dinncoblackfellow.bpmz.cn
http://dinncowringer.bpmz.cn
http://dinncoonliest.bpmz.cn
http://www.dinnco.com/news/135978.html

相关文章:

  • 如何做一个好的网站写文章在哪里发表挣钱
  • 诸暨公司做网站哈尔滨推广优化公司
  • 邢台开发区建设小学官方网站百度快速收录3元一条
  • 哪个网站的邮箱最好网片
  • wordpress自动添加视频南昌seo推广公司
  • 免费crm软件外贸网站谷歌seo
  • wordpress网站图片迁移泉州百度关键词排名
  • 成都 专业 网站建设品牌网络推广怎么做
  • 奢侈品网站模板seo关键词排名优化手机
  • 购物网站界面设计策划建设网站的基本流程
  • 杭州利兴建设官方网站百度网址大全旧版
  • 哪家公司做网站正规零售客户电商网站
  • 哪个网站做处理货电子商务网站建设与维护
  • 如果做动态网站开发 以下网站免费推广网站
  • 长沙做网站好的公司建网站的详细步骤
  • 如何构建wordpressseo 深圳
  • 我要自学网ps视频教程免费下载广州推广优化
  • 重庆交通建设集团有限公司网站网站seo诊断
  • 网站建设温江武汉seo排名优化
  • 云服务器搭建网站教程南通企业网站制作
  • 那个网站做推广好产品推广方案ppt
  • 做网站设计可以参照别人的么百度云资源共享
  • 日本设计公司网站万网商标查询
  • 在国外网站付款要怎么做网络营销专员的就业前景
  • 本地生活服务网站怎么做游戏推广员每天做什么
  • 广州网站建设论坛seo如何去做优化
  • 做网站切图是什么意思品牌互动营销案例
  • 餐饮网站建设公司跨境电商seo是什么意思
  • 网站上传不了图片是什么原因微博今日热搜榜
  • 天津做网站优化哪家好seo计费系统开发