当前位置: 首页 > 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…...

python/java环境配置

环境变量放一起 python&#xff1a; 1.首先下载Python Python下载地址&#xff1a;Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个&#xff0c;然后自定义&#xff0c;全选 可以把前4个选上 3.环境配置 1&#xff09;搜高级系统设置 2…...

376. Wiggle Subsequence

376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...

工程地质软件市场:发展现状、趋势与策略建议

一、引言 在工程建设领域&#xff0c;准确把握地质条件是确保项目顺利推进和安全运营的关键。工程地质软件作为处理、分析、模拟和展示工程地质数据的重要工具&#xff0c;正发挥着日益重要的作用。它凭借强大的数据处理能力、三维建模功能、空间分析工具和可视化展示手段&…...

使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台

🎯 使用 Streamlit 构建支持主流大模型与 Ollama 的轻量级统一平台 📌 项目背景 随着大语言模型(LLM)的广泛应用,开发者常面临多个挑战: 各大模型(OpenAI、Claude、Gemini、Ollama)接口风格不统一;缺乏一个统一平台进行模型调用与测试;本地模型 Ollama 的集成与前…...

Redis:现代应用开发的高效内存数据存储利器

一、Redis的起源与发展 Redis最初由意大利程序员Salvatore Sanfilippo在2009年开发&#xff0c;其初衷是为了满足他自己的一个项目需求&#xff0c;即需要一个高性能的键值存储系统来解决传统数据库在高并发场景下的性能瓶颈。随着项目的开源&#xff0c;Redis凭借其简单易用、…...

工厂方法模式和抽象工厂方法模式的battle

1.案例直接上手 在这个案例里面&#xff0c;我们会实现这个普通的工厂方法&#xff0c;并且对比这个普通工厂方法和我们直接创建对象的差别在哪里&#xff0c;为什么需要一个工厂&#xff1a; 下面的这个是我们的这个案例里面涉及到的接口和对应的实现类&#xff1a; 两个发…...

CVE-2023-25194源码分析与漏洞复现(Kafka JNDI注入)

漏洞概述 漏洞名称&#xff1a;Apache Kafka Connect JNDI注入导致的远程代码执行漏洞 CVE编号&#xff1a;CVE-2023-25194 CVSS评分&#xff1a;8.8 影响版本&#xff1a;Apache Kafka 2.3.0 - 3.3.2 修复版本&#xff1a;≥ 3.4.0 漏洞类型&#xff1a;反序列化导致的远程代…...

统计学(第8版)——统计抽样学习笔记(考试用)

一、统计抽样的核心内容与问题 研究内容 从总体中科学抽取样本的方法利用样本数据推断总体特征&#xff08;均值、比率、总量&#xff09;控制抽样误差与非抽样误差 解决的核心问题 在成本约束下&#xff0c;用少量样本准确推断总体特征量化估计结果的可靠性&#xff08;置…...

VASP软件在第一性原理计算中的应用-测试GO

VASP软件在第一性原理计算中的应用 VASP是由维也纳大学Hafner小组开发的一款功能强大的第一性原理计算软件&#xff0c;广泛应用于材料科学、凝聚态物理、化学和纳米技术等领域。 VASP的核心功能与应用 1. 电子结构计算 VASP最突出的功能是进行高精度的电子结构计算&#xff…...

后端下载限速(redis记录实时并发,bucket4j动态限速)

✅ 使用 Redis 记录 所有用户的实时并发下载数✅ 使用 Bucket4j 实现 全局下载速率限制&#xff08;动态&#xff09;✅ 支持 动态调整限速策略✅ 下载接口安全、稳定、可监控 &#x1f9e9; 整体架构概览 模块功能Redis存储全局并发数和带宽令牌桶状态Bucket4j Redis分布式限…...