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

苏州北京网站建设seo外包网络公司

苏州北京网站建设,seo外包网络公司,电脑上做简单的网站,wordpress保存文件路径文章目录 1.工具类2.依赖3.sql 本文档只是为了留档方便以后工作运维,或者给同事分享文档内容比较简陋命令也不是特别全,不适合小白观看,如有不懂可以私信,上班期间都是在得 背景:因为频繁操作json嵌套数据 PostgreSQL得…

文章目录

  • 1.工具类
  • 2.依赖
  • 3.sql

本文档只是为了留档方便以后工作运维,或者给同事分享文档内容比较简陋命令也不是特别全,不适合小白观看,如有不懂可以私信,上班期间都是在得

背景:因为频繁操作json嵌套数据 PostgreSQL得JSON操作记录(本来还有一份MongoDB得,但是因为电脑卡死机文档没保存下来,气的我已经摔键盘了,后续重新写在进行补充)

1.工具类

 
package com.xhao.PostgreSQL;import com.alibaba.fastjson2.JSON;
import com.jayway.jsonpath.JsonPath;
import org.springframework.util.ObjectUtils;/*** @author XHao*/
public class JsonUtils {/*** 删除Key** @param json 原json* @param path 链路*/public static Object processJsonDelete(Object json, String path) {return JsonPath.parse(JSON.parse(json.toString())).delete(path).json();}/*** 查询value** @param json 原json* @param path 链路*/public static Object getJsonValue(Object json, String path) {return JsonPath.parse(JSON.parse(json.toString())).read(path).toString();}/*** 更新/添加Json** @param json  原json* @param path  链路* @param value key*/public static Object processJsonUpdate(Object json, String path, Object value) {return JsonPath.parse(JSON.parse(json.toString())).set(path, value).json();}/*** 获取json路径** @param path 路径* @param key  key* @return 新json路径*/public static String getPath(String path, String key) {if (ObjectUtils.isEmpty(key)) {return getPath(path);} else if (key.matches("\\d+")) {return getPath(path) + "[" + key + "]";} else {return getPath(path) + "." + key;}}/*** 获取json路径** @param path 路径* @return 新json路径*/public static String getPath(String path) {String[] parts = path.split("-");StringBuilder jsonPath = new StringBuilder("$");for (String part : parts) {// 检查是否是数组索引(数字)if (part.matches("\\d+")) {jsonPath.append("[").append(part).append("]");} else {jsonPath.append(".").append(part);}}return jsonPath.toString();}public static void main(String[] args) {String str = "option-series-0-emphasis-textStyle";String str1 = null;System.err.println(getPath(str, str1));System.err.println(getPath(str));}
}

2.依赖

   <!-- Hibernate 类型扩展 --><dependency><groupId>com.vladmihalcea</groupId><artifactId>hibernate-types-52</artifactId><version>2.14.0</version></dependency><!-- JsonPath --><dependency><groupId>com.jayway.jsonpath</groupId><artifactId>json-path</artifactId><version>2.7.0</version></dependency><!-- PostgreSQL 驱动 --><dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId></dependency>

3.sql


//查询
SELECT json->'option'->'xAxis'->0->>'show' AS show_value
FROM "public".test
WHERE id = 1;//修改
UPDATE "public".test
SET json = jsonb_set(json, '{option,xAxis,0,show}', '55555'::jsonb)  -- 将数字55555转换为jsonb类型
WHERE id = 1;UPDATE "public".test
SET json = jsonb_set(json, '{option,xAxis,0,show}',  -- 指定路径为 option -> xAxis -> 0 -> show'true'::jsonb,           -- 新的值,直接使用数字类型转换为 jsonbtrue)                     -- 如果路径不存在,则创建该路径
WHERE id = 1;//删除keyUPDATE "public".test
SET json = jsonb_set(json, '{option,xAxis,0}', jsonb_strip_nulls(json->'option'->'xAxis'->0) - 'show')  -- 删除 show 键
WHERE id = 1;//添加
UPDATE "public".test
SET json = jsonb_set(json, '{option,xAxis,0,show}',  -- 指定路径为 option -> xAxis -> 0 -> showtrue::jsonb,          -- 新的值,必须转换为 jsonb 类型true)                     -- 如果路径不存在,则创建该路径
WHERE id = 1;

因为电脑卡死机导致调研文档得MongoDB得demo没了,我也很苦恼后续重新写的话在更新

如果点赞多,评论多会更新详细教程,待补充。

http://www.dtcms.com/wzjs/258940.html

相关文章:

  • 西安做网站必达网络全网关键词搜索工具
  • html的所有代码大全广东seo点击排名软件哪家好
  • 潍坊做网站建设网站收录查询爱站
  • 顺德做网站那家好微商店铺怎么开通
  • 微信网站这么做成品短视频软件大全下载手机版
  • app网站区别推广运营是做什么的
  • 广东的网站建设百度爱采购服务商查询
  • 北京中燕建设公司网站站长工具综合查询官网
  • 河海大学土木专业类建设网站什么是百度快照
  • 西安到北京飞机湖南seo服务电话
  • 河南城乡建设网站怎么自己做个网站
  • b2b网站推广优化惠州seo计费
  • 做非洲国际贸易网站互联网营销师教材
  • 网站与经营网站下拉框关键词软件
  • wordpress如何实现301跳转优化设计三年级上册答案语文
  • 摄影网站建设的目的网站模板下载免费
  • 最新的网站建设软件有哪些手机助手
  • 一级a做爰片免费网站孕交视频教程合肥关键词排名优化
  • wordpress用户中心按钮不弹出企业seo网站营销推广
  • 宣威网站建设公司济南网站建设公司
  • 做网站做推广有效果吗现在最好的免费的建站平台
  • wordpress 制作手机站百度竞价排名推广
  • 仿站多少钱一套发布平台
  • 工业设计网站哪家好5118
  • 网站开发的方案网络营销公司注册找哪家
  • 商旅平台app官网下载厦门seo外包
  • 苏州网站推广建设百度seo2022
  • 宾馆网站制作北京全网营销推广
  • 广东快速做网站公司哪家好长沙网站关键词排名公司
  • 江西做网站找谁湘潭网站设计外包服务