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

Proto文件如何生成JavaProto对象?

首先安装好Protocol Buffer的编译器

Protocol Buffer:
version:2.6.1
link: 链接直达
在这里插入图片描述
根据电脑环境进行下载,Widnwos 32/64位就选择win32是没问题的,楼主亲测

1.proto文件编写

Person.proto

public class Person  {String name;int id;String email;
}
syntax = "proto2";
option java_outer_classname="PersonPOJO";
message Person {required string name = 1;required int32 id = 2;required string email = 3;
}

2.生成PersonProto文件

接下来我们要根据上面编写好的Person.proto文件生成Java对应的Proto对象

运行指令

.\protoc.exe --java_out=. Person.proto

在这里插入图片描述
如果没有报错就是成功了,有的运行指令会报错
在这里插入图片描述
再仔细核对下上面的proto文件即可,这里采用的proto2版本进行生成的,一定要注意版本号的区别,我们下载的版本号就是2.6.1,不同的编译文件可能会有略微差异,但是不影响。

3.PersonPOJO.java

上面的JavaProto文件类名我指定成了PersonPOJO(也就是JavaProto对象),这里可以看到,里面生成了很多代码,而我们Person实体类属性才只有3个

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: Person.protopublic final class PersonPOJO {private PersonPOJO() {}public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {}public interface PersonOrBuilder extends// @@protoc_insertion_point(interface_extends:Person)com.google.protobuf.MessageOrBuilder {/*** <code>required string name = 1;</code>*/boolean hasName();/*** <code>required string name = 1;</code>*/java.lang.String getName();/*** <code>required string name = 1;</code>*/com.google.protobuf.ByteStringgetNameBytes();/*** <code>required int32 id = 2;</code>*/boolean hasId();/*** <code>required int32 id = 2;</code>*/int getId();/*** <code>required string email = 3;</code>*/boolean hasEmail();/*** <code>required string email = 3;</code>*/java.lang.String getEmail();/*** <code>required string email = 3;</code>*/com.google.protobuf.ByteStringgetEmailBytes();}/*** Protobuf type {@code Person}*/public static final class Person extendscom.google.protobuf.GeneratedMessage implements// @@protoc_insertion_point(message_implements:Person)PersonOrBuilder {// Use Person.newBuilder() to construct.private Person(com.google.protobuf.GeneratedMessage.Builder<?> builder) {super(builder);this.unknownFields = builder.getUnknownFields();}private Person(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }private static final Person defaultInstance;public static Person getDefaultInstance() {return defaultInstance;}public Person getDefaultInstanceForType() {return defaultInstance;}private final com.google.protobuf.UnknownFieldSet unknownFields;@java.lang.Overridepublic final com.google.protobuf.UnknownFieldSetgetUnknownFields() {return this.unknownFields;}private Person(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {initFields();int mutable_bitField0_ = 0;com.google.protobuf.UnknownFieldSet.Builder unknownFields =com.google.protobuf.UnknownFieldSet.newBuilder();try {boolean done = false;while (!done) {int tag = input.readTag();switch (tag) {case 0:done = true;break;default: {if (!parseUnknownField(input, unknownFields,extensionRegistry, tag)) {done = true;}break;}case 10: {com.google.protobuf.ByteString bs = input.readBytes();bitField0_ |= 0x00000001;name_ = bs;break;}case 16: {bitField0_ |= 0x00000002;id_ = input.readInt32();break;}case 26: {com.google.protobuf.ByteString bs = input.readBytes();bitField0_ |= 0x00000004;email_ = bs;break;}}}} catch (com.google.protobuf.InvalidProtocolBufferException e) {throw e.setUnfinishedMessage(this);} catch (java.io.IOException e) {throw new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(this);} finally {this.unknownFields = unknownFields.build();makeExtensionsImmutable();}}public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return PersonPOJO.internal_static_Person_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return PersonPOJO.internal_static_Person_fieldAccessorTable.ensureFieldAccessorsInitialized(PersonPOJO.Person.class, PersonPOJO.Person.Builder.class);}public static com.google.protobuf.Parser<Person> PARSER =new com.google.protobuf.AbstractParser<Person>() {public Person parsePartialFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return new Person(input, extensionRegistry);}};@java.lang.Overridepublic com.google.protobuf.Parser<Person> getParserForType() {return PARSER;}private int bitField0_;public static final int NAME_FIELD_NUMBER = 1;private java.lang.Object name_;/*** <code>required string name = 1;</code>*/public boolean hasName() {return ((bitField0_ & 0x00000001) == 0x00000001);}/*** <code>required string name = 1;</code>*/public java.lang.String getName() {java.lang.Object ref = name_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();if (bs.isValidUtf8()) {name_ = s;}return s;}}/*** <code>required string name = 1;</code>*/public com.google.protobuf.ByteStringgetNameBytes() {java.lang.Object ref = name_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);name_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}public static final int ID_FIELD_NUMBER = 2;private int id_;/*** <code>required int32 id = 2;</code>*/public boolean hasId() {return ((bitField0_ & 0x00000002) == 0x00000002);}/*** <code>required int32 id = 2;</code>*/public int getId() {return id_;}public static final int EMAIL_FIELD_NUMBER = 3;private java.lang.Object email_;/*** <code>required string email = 3;</code>*/public boolean hasEmail() {return ((bitField0_ & 0x00000004) == 0x00000004);}/*** <code>required string email = 3;</code>*/public java.lang.String getEmail() {java.lang.Object ref = email_;if (ref instanceof java.lang.String) {return (java.lang.String) ref;} else {com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();if (bs.isValidUtf8()) {email_ = s;}return s;}}/*** <code>required string email = 3;</code>*/public com.google.protobuf.ByteStringgetEmailBytes() {java.lang.Object ref = email_;if (ref instanceof java.lang.String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);email_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}private void initFields() {name_ = "";id_ = 0;email_ = "";}private byte memoizedIsInitialized = -1;public final boolean isInitialized() {byte isInitialized = memoizedIsInitialized;if (isInitialized == 1) return true;if (isInitialized == 0) return false;if (!hasName()) {memoizedIsInitialized = 0;return false;}if (!hasId()) {memoizedIsInitialized = 0;return false;}if (!hasEmail()) {memoizedIsInitialized = 0;return false;}memoizedIsInitialized = 1;return true;}public void writeTo(com.google.protobuf.CodedOutputStream output)throws java.io.IOException {getSerializedSize();if (((bitField0_ & 0x00000001) == 0x00000001)) {output.writeBytes(1, getNameBytes());}if (((bitField0_ & 0x00000002) == 0x00000002)) {output.writeInt32(2, id_);}if (((bitField0_ & 0x00000004) == 0x00000004)) {output.writeBytes(3, getEmailBytes());}getUnknownFields().writeTo(output);}private int memoizedSerializedSize = -1;public int getSerializedSize() {int size = memoizedSerializedSize;if (size != -1) return size;size = 0;if (((bitField0_ & 0x00000001) == 0x00000001)) {size += com.google.protobuf.CodedOutputStream.computeBytesSize(1, getNameBytes());}if (((bitField0_ & 0x00000002) == 0x00000002)) {size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, id_);}if (((bitField0_ & 0x00000004) == 0x00000004)) {size += com.google.protobuf.CodedOutputStream.computeBytesSize(3, getEmailBytes());}size += getUnknownFields().getSerializedSize();memoizedSerializedSize = size;return size;}private static final long serialVersionUID = 0L;@java.lang.Overrideprotected java.lang.Object writeReplace()throws java.io.ObjectStreamException {return super.writeReplace();}public static PersonPOJO.Person parseFrom(com.google.protobuf.ByteString data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static PersonPOJO.Person parseFrom(com.google.protobuf.ByteString data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static PersonPOJO.Person parseFrom(byte[] data)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data);}public static PersonPOJO.Person parseFrom(byte[] data,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws com.google.protobuf.InvalidProtocolBufferException {return PARSER.parseFrom(data, extensionRegistry);}public static PersonPOJO.Person parseFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static PersonPOJO.Person parseFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public static PersonPOJO.Person parseDelimitedFrom(java.io.InputStream input)throws java.io.IOException {return PARSER.parseDelimitedFrom(input);}public static PersonPOJO.Person parseDelimitedFrom(java.io.InputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseDelimitedFrom(input, extensionRegistry);}public static PersonPOJO.Person parseFrom(com.google.protobuf.CodedInputStream input)throws java.io.IOException {return PARSER.parseFrom(input);}public static PersonPOJO.Person parseFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {return PARSER.parseFrom(input, extensionRegistry);}public static Builder newBuilder() { return Builder.create(); }public Builder newBuilderForType() { return newBuilder(); }public static Builder newBuilder(PersonPOJO.Person prototype) {return newBuilder().mergeFrom(prototype);}public Builder toBuilder() { return newBuilder(this); }@java.lang.Overrideprotected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) {Builder builder = new Builder(parent);return builder;}/*** Protobuf type {@code Person}*/public static final class Builder extendscom.google.protobuf.GeneratedMessage.Builder<Builder> implements// @@protoc_insertion_point(builder_implements:Person)PersonPOJO.PersonOrBuilder {public static final com.google.protobuf.Descriptors.DescriptorgetDescriptor() {return PersonPOJO.internal_static_Person_descriptor;}protected com.google.protobuf.GeneratedMessage.FieldAccessorTableinternalGetFieldAccessorTable() {return PersonPOJO.internal_static_Person_fieldAccessorTable.ensureFieldAccessorsInitialized(PersonPOJO.Person.class, PersonPOJO.Person.Builder.class);}// Construct using PersonPOJO.Person.newBuilder()private Builder() {maybeForceBuilderInitialization();}private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) {super(parent);maybeForceBuilderInitialization();}private void maybeForceBuilderInitialization() {if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {}}private static Builder create() {return new Builder();}public Builder clear() {super.clear();name_ = "";bitField0_ = (bitField0_ & ~0x00000001);id_ = 0;bitField0_ = (bitField0_ & ~0x00000002);email_ = "";bitField0_ = (bitField0_ & ~0x00000004);return this;}public Builder clone() {return create().mergeFrom(buildPartial());}public com.google.protobuf.Descriptors.DescriptorgetDescriptorForType() {return PersonPOJO.internal_static_Person_descriptor;}public PersonPOJO.Person getDefaultInstanceForType() {return PersonPOJO.Person.getDefaultInstance();}public PersonPOJO.Person build() {PersonPOJO.Person result = buildPartial();if (!result.isInitialized()) {throw newUninitializedMessageException(result);}return result;}public PersonPOJO.Person buildPartial() {PersonPOJO.Person result = new PersonPOJO.Person(this);int from_bitField0_ = bitField0_;int to_bitField0_ = 0;if (((from_bitField0_ & 0x00000001) == 0x00000001)) {to_bitField0_ |= 0x00000001;}result.name_ = name_;if (((from_bitField0_ & 0x00000002) == 0x00000002)) {to_bitField0_ |= 0x00000002;}result.id_ = id_;if (((from_bitField0_ & 0x00000004) == 0x00000004)) {to_bitField0_ |= 0x00000004;}result.email_ = email_;result.bitField0_ = to_bitField0_;onBuilt();return result;}public Builder mergeFrom(com.google.protobuf.Message other) {if (other instanceof PersonPOJO.Person) {return mergeFrom((PersonPOJO.Person)other);} else {super.mergeFrom(other);return this;}}public Builder mergeFrom(PersonPOJO.Person other) {if (other == PersonPOJO.Person.getDefaultInstance()) return this;if (other.hasName()) {bitField0_ |= 0x00000001;name_ = other.name_;onChanged();}if (other.hasId()) {setId(other.getId());}if (other.hasEmail()) {bitField0_ |= 0x00000004;email_ = other.email_;onChanged();}this.mergeUnknownFields(other.getUnknownFields());return this;}public final boolean isInitialized() {if (!hasName()) {return false;}if (!hasId()) {return false;}if (!hasEmail()) {return false;}return true;}public Builder mergeFrom(com.google.protobuf.CodedInputStream input,com.google.protobuf.ExtensionRegistryLite extensionRegistry)throws java.io.IOException {PersonPOJO.Person parsedMessage = null;try {parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);} catch (com.google.protobuf.InvalidProtocolBufferException e) {parsedMessage = (PersonPOJO.Person) e.getUnfinishedMessage();throw e;} finally {if (parsedMessage != null) {mergeFrom(parsedMessage);}}return this;}private int bitField0_;private java.lang.Object name_ = "";/*** <code>required string name = 1;</code>*/public boolean hasName() {return ((bitField0_ & 0x00000001) == 0x00000001);}/*** <code>required string name = 1;</code>*/public java.lang.String getName() {java.lang.Object ref = name_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();if (bs.isValidUtf8()) {name_ = s;}return s;} else {return (java.lang.String) ref;}}/*** <code>required string name = 1;</code>*/public com.google.protobuf.ByteStringgetNameBytes() {java.lang.Object ref = name_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);name_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>required string name = 1;</code>*/public Builder setName(java.lang.String value) {if (value == null) {throw new NullPointerException();}bitField0_ |= 0x00000001;name_ = value;onChanged();return this;}/*** <code>required string name = 1;</code>*/public Builder clearName() {bitField0_ = (bitField0_ & ~0x00000001);name_ = getDefaultInstance().getName();onChanged();return this;}/*** <code>required string name = 1;</code>*/public Builder setNameBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}bitField0_ |= 0x00000001;name_ = value;onChanged();return this;}private int id_ ;/*** <code>required int32 id = 2;</code>*/public boolean hasId() {return ((bitField0_ & 0x00000002) == 0x00000002);}/*** <code>required int32 id = 2;</code>*/public int getId() {return id_;}/*** <code>required int32 id = 2;</code>*/public Builder setId(int value) {bitField0_ |= 0x00000002;id_ = value;onChanged();return this;}/*** <code>required int32 id = 2;</code>*/public Builder clearId() {bitField0_ = (bitField0_ & ~0x00000002);id_ = 0;onChanged();return this;}private java.lang.Object email_ = "";/*** <code>required string email = 3;</code>*/public boolean hasEmail() {return ((bitField0_ & 0x00000004) == 0x00000004);}/*** <code>required string email = 3;</code>*/public java.lang.String getEmail() {java.lang.Object ref = email_;if (!(ref instanceof java.lang.String)) {com.google.protobuf.ByteString bs =(com.google.protobuf.ByteString) ref;java.lang.String s = bs.toStringUtf8();if (bs.isValidUtf8()) {email_ = s;}return s;} else {return (java.lang.String) ref;}}/*** <code>required string email = 3;</code>*/public com.google.protobuf.ByteStringgetEmailBytes() {java.lang.Object ref = email_;if (ref instanceof String) {com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);email_ = b;return b;} else {return (com.google.protobuf.ByteString) ref;}}/*** <code>required string email = 3;</code>*/public Builder setEmail(java.lang.String value) {if (value == null) {throw new NullPointerException();}bitField0_ |= 0x00000004;email_ = value;onChanged();return this;}/*** <code>required string email = 3;</code>*/public Builder clearEmail() {bitField0_ = (bitField0_ & ~0x00000004);email_ = getDefaultInstance().getEmail();onChanged();return this;}/*** <code>required string email = 3;</code>*/public Builder setEmailBytes(com.google.protobuf.ByteString value) {if (value == null) {throw new NullPointerException();}bitField0_ |= 0x00000004;email_ = value;onChanged();return this;}// @@protoc_insertion_point(builder_scope:Person)}static {defaultInstance = new Person(true);defaultInstance.initFields();}// @@protoc_insertion_point(class_scope:Person)}private static final com.google.protobuf.Descriptors.Descriptorinternal_static_Person_descriptor;private staticcom.google.protobuf.GeneratedMessage.FieldAccessorTableinternal_static_Person_fieldAccessorTable;public static com.google.protobuf.Descriptors.FileDescriptorgetDescriptor() {return descriptor;}private static com.google.protobuf.Descriptors.FileDescriptordescriptor;static {java.lang.String[] descriptorData = {"\n\014Person.proto\"1\n\006Person\022\014\n\004name\030\001 \002(\t\022\n" +"\n\002id\030\002 \002(\005\022\r\n\005email\030\003 \002(\tB\014B\nPersonPOJO"};com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =new com.google.protobuf.Descriptors.FileDescriptor.    InternalDescriptorAssigner() {public com.google.protobuf.ExtensionRegistry assignDescriptors(com.google.protobuf.Descriptors.FileDescriptor root) {descriptor = root;return null;}};com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData,new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner);internal_static_Person_descriptor =getDescriptor().getMessageTypes().get(0);internal_static_Person_fieldAccessorTable = newcom.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_Person_descriptor,new java.lang.String[] { "Name", "Id", "Email", });}// @@protoc_insertion_point(outer_class_scope)
}

4.性能比较

再验证之前pom.xml文件需要导入和我们上面protoc.exe一样的版本号,否则可能会出错,上面的protoc.exe使用的是2.6.1,pom文件也用2.6.1

        <dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId><version>2.6.1</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.66</version></dependency>

这里我们再加上FASTJSON,进行三者之间的对比

package cn.tuling.nettybasic.serializable.protobuf;import com.alibaba.fastjson.JSON;import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;public class PerformTest {public static void main(String[] args) throws IOException {long start1 = System.currentTimeMillis();PersonOuterClass.Person person = PersonOuterClass.Person.newBuilder().setId(1).setName("Cover").setEmail("xxxxx@gmail.com").build();byte[] result = person.toByteArray();long end1 = System.currentTimeMillis();System.out.println("Proto serialize length:" + result.length + ", time :" + (end1 - start1));// FAST JSONlong start3 = System.currentTimeMillis();Person person2 = new Person();person2.id = 2;person2.name = "Cover";person2.email = "xxxxx@gmail.com";byte[] bytes = JSON.toJSONString(person2).getBytes();long end3 = System.currentTimeMillis();System.out.println("FASTJSON serialize length: " + bytes.length + ", time :" + (end3 - start3));// JDKlong start2 = System.currentTimeMillis();Person person1 = new Person();person1.id = 2;person1.name = "Cover";person1.email = "xxxxx@gmail.com";ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();ObjectOutputStream out = new ObjectOutputStream(arrayOutputStream);out.writeObject(person1);long end2 = System.currentTimeMillis();System.out.println("JDK serialize length:" + arrayOutputStream.toByteArray().length + ", time :" + (end2 - start2));}
}

5.序列化结果展示

在这里插入图片描述
可以看到,Proto性能在空间复杂度和时间复杂度上总体要比FASTJSON和JDK要有优势,其实还有很多框架序列化和反序列化的性能也不错,下期我们再介绍其他几种框架,Proto的方式相比其他框架要麻烦一点,需要下载特定的编译器才行。它这样做的目的是为了方便地支持跨语言。

相关文章:

Proto文件如何生成JavaProto对象?

首先安装好Protocol Buffer的编译器 Protocol Buffer: version:2.6.1 link: 链接直达 根据电脑环境进行下载&#xff0c;Widnwos 32/64位就选择win32是没问题的&#xff0c;楼主亲测 1.proto文件编写 Person.proto public class Person {String name;int id;String email…...

LightDB 24.1 UNION支持null类型匹配

背景介绍 在LightDB 24.1之前的版本&#xff0c;UNION null类型匹配会报错。 lightdbpostgres# select null l_zqlbmx2 union all select null l_zqlbmx2 union all select sysdate l_zqlbmx; ERROR: UNION types text and timestamp without time zone…...

使用vs2022将.net8的应用程序发布为一个单独文件

在使用.NetCore3.1时&#xff0c;可以通过设置以下工程配置文本来将项目发布为一个单独的应用程序文件&#xff1a; <Project Sdk"Microsoft.NET.Sdk.WindowsDesktop"><PropertyGroup><TargetFramework>netcoreapp3.1</TargetFramework><…...

面试经典150题(93-95)

leetcode 150道题 计划花两个月时候刷完&#xff0c;今天&#xff08;第五十三天&#xff09;完成了3道(93-95)150&#xff1a; 93.&#xff08;53. 最大子数组和&#xff09;题目描述&#xff1a; 给你一个整数数组 nums &#xff0c;请你找出一个具有最大和的连续子数组&am…...

flask 实现token生成以及携带token请求接口

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、Flask-JWT-Extended是什么&#xff1f;二、使用步骤1.引入库2.请求验证 总结 前言 提示&#xff1a;这里可以添加本文要记录的大概内容&#xff1a; 提示&…...

docker-compose部署单机ES+Kibana

记录部署的操作步骤 准备工作编写docker-compose.yml启动服务验证部署结果 本次elasticsearch和kibana版本为8.2.2 使用环境&#xff1a;centos7.9 本次记录还包括&#xff1a;安装elasticsearch中文分词插件和拼音分词插件 准备工作 1、创建目录和填写配置 mkdir /home/es/s…...

gitee仓库项目迁移到gitlab仓库

背景 之前一直使用gitee代码仓库提交代码&#xff0c;现在需要将gitee仓库中的代码迁移到gitlab中&#xff0c;并保留原有的提交记录。 前提 配置好了本地git&#xff0c;并本地与gitlab仓库已连接。 我这里使用 ssh方式拉去代码&#xff0c;因此需要配置ssh密钥 步骤 也可以直…...

安装elasticsearch、kibana、IK分词器

1.部署单点es 1.1.创建网络 因为我们还需要部署kibana容器&#xff0c;因此需要让es和kibana容器互联。这里先创建一个网络&#xff1a; docker network create es-net 1.2.加载镜像 这里我们采用elasticsearch的7.12.1版本的镜像&#xff0c;这个镜像体积非常大&#xff0…...

海外云手机运营Instagram攻略

Instagram是世界著名的社交媒体平台&#xff0c;有着10亿实时用户&#xff0c;是跨境电子商务的优质流量来源。平台以女性用户为主&#xff0c;购物倾向高&#xff0c;转化率好。它被公认为外贸行业的优质社交媒体流量池。那么&#xff0c;如何使用海外云手机吸引Instagram上的…...

【lesson25】学习MySQL事务前的基础知识

文章目录 CURD不加控制&#xff0c;会有什么问题&#xff1f;CURD满足什么属性&#xff0c;能解决上述问题&#xff1f;什么是事务&#xff1f;为什么会出现事务事务的版本支持 CURD不加控制&#xff0c;会有什么问题&#xff1f; CURD满足什么属性&#xff0c;能解决上述问题&…...

SkyWalking+es部署与使用

第一步下载skywalking :http://skywalking.apache.org/downloads/ 第二步下载es:https://www.elastic.co/cn/downloads/elasticsearch 注&#xff1a;skywalking 和es要版本对应&#xff0c;可从下面连接查看版本对应关系&#xff0c;8.5.0为skywalking 版本号 Index of /di…...

js获取html中的img标签,图片标签,提取src属性并替换操作

场景&#xff1a; 获取HTML中的所有图片标签&#xff0c;并把图片的src属性替换成webp图片, 若浏览器支持webp&#xff0c;则展示&#xff0c;不支持走onerror函数展示data-original原图。 function getDetailWebp(htmlStr, width 600){if(!htmlStr) return ;var reg /<im…...

【力扣经典面试题】27. 移除元素

题目描述&#xff1a; 给你一个数组 nums 和一个值 val&#xff0c;你需要 原地 移除所有数值等于 val 的元素&#xff0c;并返回移除后数组的新长度。 不要使用额外的数组空间&#xff0c;你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺序可以改变。你不需要考虑…...

MicrosoftEdge浏览器打开网页出现“此网站被人举报不安全”问题时解决办法

1&#xff1a;有时候不知怎么回事用电脑自带的微软浏览器进行搜索会出现以下的问题 这可能是由于我们的浏览器安全审查过于严格引起的 Windows10正式版系统下&#xff0c;使用Edge浏览器浏览网页时候&#xff0c;发现整个页面突然变成了红色&#xff0c;显示“已有人举报此网站…...

【PyCharm教程】PyCharm 安装、卸载和升级包

PyCharm 为特定的 Python 解释器提供了安装、卸载和升级 Python 包的方法。默认情况下&#xff0c;PyCharm 使用 pip 来管理项目包。对于 Conda 环境&#xff0c;您可以使用conda 包管理器。 在 PyCharm 中&#xff0c;您可以在Python 包工具窗口和 Python 解释器Settings/Pre…...

蓝桥杯-常用STL(一)

常用STL &#x1f388;1.动态数组&#x1f388;2.vector的基础使用&#x1f52d;2.1引入库&#x1f52d;2.2构造一个动态数组&#x1f52d;2.3插入元素&#x1f52d;2.4获取长度并且访问元素&#x1f52d;2.5修改元素&#x1f52d;2.6删除元素&#x1f52d;2.7清空 &#x1f38…...

SQL查询数据库环境(dm8达梦数据库)

SQL查询数据库环境dm8达梦数据库 环境介绍 环境介绍 某些环境没有图形化界面,可以使用sql语句查询达梦数据库环境情况 SELECT 实例名称 数据库选项,INSTANCE_NAME 数据库选项相关参数值 FROM V$INSTANCE UNION ALL SELECT 授权用户,(SELECT AUTHORIZED_CUSTOMER FROM V$LICE…...

DolphinScheduler + Amazon EMR Serverless 的集成实践

01 背景 Apache DolphinScheduler 是一个分布式的可视化 DAG 工作流任务调度开源系统&#xff0c;具有简单易用、高可靠、高扩展性、⽀持丰富的使用场景、提供多租户模式等特性。适用于企业级场景&#xff0c;提供了一个可视化操作任务、工作流和全生命周期数据处理过程的解决方…...

【服务器APP】利用HBuilder X把网页打包成APP

目录 &#x1f33a;1. 概述 &#x1f33c;1.1 新建项目 &#x1f33c;1.2 基础配置 &#x1f33c;1.3 图标配置 &#x1f33c;1.4 启动界面配置 &#x1f33c;1.5 模块配置 &#x1f33c;1.6 打包成APP &#x1f33a;1. 概述 探讨如何将网页转化为APP&#xff0c;这似乎…...

vue3 组合式API获取子组件的属性和方法

在vue2中&#xff0c;获取子组件实例的方法或者属性时&#xff0c;父组件直接通过ref即可直接获取子组件的属性和方法&#xff0c;如下&#xff1a; // father.vue <child ref"instanceRef" /> this.$ref[instanceRef].testVal this.$ref[instanceRef].testFun…...

[数据结构+算法] 给一棵树和一个sum,判断是否存在从root到叶子结点的path之和等于sum?

[数据结构算法] 给一棵树和一个sum&#xff0c;判断是否存在从root到叶子结点的path之和等于sum&#xff1f; 可以使用两种方法求解 递归 CheckTreeSumRecursive 问题转换为递归判断左右子树是否满足路径和等于sum减去当前节点的值。 迭代 CheckTreeSumNonRecursive 使用两个…...

非阿里云注册域名如何在云解析DNS设置解析?

概述 非阿里云注册域名使用云解析DNS&#xff0c;按照如下步骤&#xff1a; 添加域名。 添加解析记录。 修改DNS服务器。 DNS服务器变更全球同步&#xff0c;等待48小时。 添加解析记录 登录云解析DNS产品控制台。 在 域名解析 页面中&#xff0c;单击 添加域名 。 在 …...

微服务-微服务Alibaba-Nacos注册中心实现

1. 系统架构的演变 俗话说&#xff0c; 没有最好的架构&#xff0c;只有最合适的架构。 微服务架构也是随着信息产业的发展而出现的最有普 遍适用性的一套架构模式。通常来说&#xff0c;我们认为架构发展历史经历了这样一个过程&#xff1a;单体架构——> 垂直架构 ——&g…...

多符号表达式的共同子表达式提取教程

生成的符号表达式&#xff0c;可能会存在过于冗长的问题&#xff0c;且多个符号表达式中&#xff0c;有可能存在相同的计算部分&#xff0c;如果不进行处理&#xff0c;计算过程中会导致某些算式计算多次&#xff0c;从而影响计算效率。 那么多个符号表达式生成函数时&#xf…...

Java 反射获取属性名、属性类型、属性值、判断属性类型

1.代码 /*** 通过反射获取对象属性名、属性类型、属性值** param t 需要反射的对象* author hcx*/public static <T> void reflect(T t){// 获取所有属性// getDeclaredFields 不包含父类&#xff0c;包含私有属性// getFields 包含父类属性Field[] fields t.getClass(…...

Docker私有仓库搭建

目录 1.registry私有仓库 拉取registry镜像 修改docker配置文件并重启 运行registry容器 修改想要上传的镜像的标签并上传验证 再另一台主机上获取此镜像 浏览器验证 2.Docker--harbor私有仓库部署与管理 什么是Harbor Harbor的特性 Harbor的构成 Harbor部署 准备…...

C语言第十三弹---VS使用调试技巧

✨个人主页&#xff1a; 熬夜学编程的小林 &#x1f497;系列专栏&#xff1a; 【C语言详解】 【数据结构详解】 VS调试技巧 1、什么是bug 2、什么是调试&#xff08;debug&#xff09;&#xff1f; 3、Debug和Release​编辑​ 4、VS调试快捷键 4.1、环境准备 4.2、调试…...

AST反混淆实战-jsjiamiv7最高配置

js加密混淆网站 https://www.jsjiami.com/一、混淆demo生成 01 打开目标网址 https://www.jsjiami.com/ 02 按照顺序加密混淆二、混淆前后demo 混淆前的源码 (function(w, d) { w.update "2023年01月17日05:34:29更新"; d.info "本站历时1年半研发的新版本V7…...

colorThief+vite+react使用方法

官网: Color Thief npm i --save colorthief 第一种,import载入图片 经过尝试,在vite中,要引入.mjs版本 import ColorThief from colorthief/dist/color-thief.mjs 第一种,通过import载入图片 import aa from /assets/123.jpgconst [resultColor,setResultColor]useState() …...

Hive(15)中使用sum() over()实现累积求和和滑动求和

目的&#xff1a; 三个常用的排序函数row_number(),rank()和dense_rank()。这三个函数需要配合开窗函数over()来实现排序功能。但over()的用法远不止于此&#xff0c;本文咱们来介绍如何实现累计求和和滑动求和。 1、数据介绍 三列数据&#xff0c;分别是员工的姓名、月份和…...