gRPC远程调用服务端与客户端连接详解

news2024/10/6 1:58:47

proto插件生成文件

参考之前的文章构建一个grpc实例,初步认识gprcgRPC教程与应用。

首先早gprc中下载了protoc插件,然后编写了.proto配置文件,通过插件生成了xxx.pb.goxxx_gprc.pb.go两个文件。前者是rpc服务器请求和响应参数的定义,后者是服务方法的定义包含构建服务器实例。

syntax = "proto3";

//编译为对应语言
//option java_package = "io.grpc.examples";
option go_package = "./;protoInterface";

package protoInterface;

// 定义接口
service Interface {
  // 方法1
  rpc GetProduct (Request) returns (Response) {}
  // 方法2
  rpc Util (Request) returns (Response) {}

}

// 定义数据类型
message Request {
  string paramString = 1;
}

//
message Response {
  string messageString = 1;
}

参数文件

在上述proto文件中,service定义了一个接口包含GetProductUtil两个方法,message定义了两个结构体参数Request请求参数和Response响应参数。

message定义的参数会生成在xxx.pb.go文件中,如下代码:

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.28.1
// 	protoc        v3.20.1
// source: build.proto

package protoInterface

import (
	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
	reflect "reflect"
	sync "sync"
)

const (
	// Verify that this generated code is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
	// Verify that runtime/protoimpl is sufficiently up-to-date.
	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)

// 定义数据类型
type Request struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	ParamString string `protobuf:"bytes,1,opt,name=paramString,proto3" json:"paramString,omitempty"`
}

func (x *Request) Reset() {
	*x = Request{}
	if protoimpl.UnsafeEnabled {
		mi := &file_build_proto_msgTypes[0]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Request) String() string {
	return protoimpl.X.MessageStringOf(x)
}

func (*Request) ProtoMessage() {}

func (x *Request) ProtoReflect() protoreflect.Message {
	mi := &file_build_proto_msgTypes[0]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
	return file_build_proto_rawDescGZIP(), []int{0}
}

func (x *Request) GetParamString() string {
	if x != nil {
		return x.ParamString
	}
	return ""
}

type Response struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	MessageString string `protobuf:"bytes,1,opt,name=messageString,proto3" json:"messageString,omitempty"`
}

func (x *Response) Reset() {
	*x = Response{}
	if protoimpl.UnsafeEnabled {
		mi := &file_build_proto_msgTypes[1]
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		ms.StoreMessageInfo(mi)
	}
}

func (x *Response) String() string {
	return protoimpl.X.MessageStringOf(x)
}

func (*Response) ProtoMessage() {}

func (x *Response) ProtoReflect() protoreflect.Message {
	mi := &file_build_proto_msgTypes[1]
	if protoimpl.UnsafeEnabled && x != nil {
		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
		if ms.LoadMessageInfo() == nil {
			ms.StoreMessageInfo(mi)
		}
		return ms
	}
	return mi.MessageOf(x)
}

// Deprecated: Use Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
	return file_build_proto_rawDescGZIP(), []int{1}
}

func (x *Response) GetMessageString() string {
	if x != nil {
		return x.MessageString
	}
	return ""
}

var File_build_proto protoreflect.FileDescriptor

var file_build_proto_rawDesc = []byte{
	0x0a, 0x0b, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x70,
	0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x2b, 0x0a,
	0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x61,
	0x6d, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70,
	0x61, 0x72, 0x61, 0x6d, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x30, 0x0a, 0x08, 0x52, 0x65,
	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
	0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6d,
	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x32, 0x8f, 0x01, 0x0a,
	0x09, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x0a, 0x47, 0x65,
	0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
	0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
	0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61,
	0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a,
	0x08, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74,
	0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
	0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66,
	0x61, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x13,
	0x5a, 0x11, 0x2e, 0x2f, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66,
	0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (
	file_build_proto_rawDescOnce sync.Once
	file_build_proto_rawDescData = file_build_proto_rawDesc
)

func file_build_proto_rawDescGZIP() []byte {
	file_build_proto_rawDescOnce.Do(func() {
		file_build_proto_rawDescData = protoimpl.X.CompressGZIP(file_build_proto_rawDescData)
	})
	return file_build_proto_rawDescData
}

var file_build_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_build_proto_goTypes = []interface{}{
	(*Request)(nil),  // 0: protoInterface.Request
	(*Response)(nil), // 1: protoInterface.Response
}
var file_build_proto_depIdxs = []int32{
	0, // 0: protoInterface.Interface.GetProduct:input_type -> protoInterface.Request
	0, // 1: protoInterface.Interface.Util:input_type -> protoInterface.Request
	1, // 2: protoInterface.Interface.GetProduct:output_type -> protoInterface.Response
	1, // 3: protoInterface.Interface.Util:output_type -> protoInterface.Response
	2, // [2:4] is the sub-list for method output_type
	0, // [0:2] is the sub-list for method input_type
	0, // [0:0] is the sub-list for extension type_name
	0, // [0:0] is the sub-list for extension extendee
	0, // [0:0] is the sub-list for field type_name
}

func init() { file_build_proto_init() }
func file_build_proto_init() {
	if File_build_proto != nil {
		return
	}
	if !protoimpl.UnsafeEnabled {
		file_build_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Request); i {
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
		file_build_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
			switch v := v.(*Response); i {
			case 0:
				return &v.state
			case 1:
				return &v.sizeCache
			case 2:
				return &v.unknownFields
			default:
				return nil
			}
		}
	}
	type x struct{}
	out := protoimpl.TypeBuilder{
		File: protoimpl.DescBuilder{
			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
			RawDescriptor: file_build_proto_rawDesc,
			NumEnums:      0,
			NumMessages:   2,
			NumExtensions: 0,
			NumServices:   1,
		},
		GoTypes:           file_build_proto_goTypes,
		DependencyIndexes: file_build_proto_depIdxs,
		MessageInfos:      file_build_proto_msgTypes,
	}.Build()
	File_build_proto = out.File
	file_build_proto_rawDesc = nil
	file_build_proto_goTypes = nil
	file_build_proto_depIdxs = nil
}


生成大内容很多,这里主要看如何从请求提供获取参数,以及将数据返回给响应体,核心代码如下:

// 定义数据类型
type Request struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	ParamString string `protobuf:"bytes,1,opt,name=paramString,proto3" json:"paramString,omitempty"`
}

func (x *Request) GetParamString() string {
	if x != nil {
		return x.ParamString
	}
	return ""
}

type Response struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	MessageString string `protobuf:"bytes,1,opt,name=messageString,proto3" json:"messageString,omitempty"`
}

func (x *Response) GetMessageString() string {
	if x != nil {
		return x.MessageString
	}
	return ""
}

上述代码实现了从请求体中获取请求参数,和设置响应体数据。

HTTP传输的是字符串,到了TCP层以二进制传输。
对于使用HTTP协议传输图片、文件,则有一个将二进制通过Base64等编码方式转换为字符串的过程。

http传输的基本单元是文本数据也就是字符流,所以需要有序列化和反序列化的过程。大多数框架都自动完成了这一步骤,只需要返回结构体数据就行。

方法文件

方法文件中包含了构建rpc服务器与客户端实例的方法,以及相关的api用于获取服务端方法,客户端接受服务器端返回值的方法。方法文件一般都以XXX_grpc.pb.go命名。

//源码
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc             v3.20.1
// source: build.proto

package protoInterface

import (
	context "context"
	grpc "google.golang.org/grpc"
	codes "google.golang.org/grpc/codes"
	status "google.golang.org/grpc/status"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7

// InterfaceClient is the client API for Interface service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type InterfaceClient interface {
	// 方法1
	GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
	// 方法2
	Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}

type interfaceClient struct {
	cc grpc.ClientConnInterface
}

func NewInterfaceClient(cc grpc.ClientConnInterface) InterfaceClient {
	return &interfaceClient{cc}
}

func (c *interfaceClient) GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
	out := new(Response)
	err := c.cc.Invoke(ctx, "/protoInterface.Interface/GetProduct", in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *interfaceClient) Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
	out := new(Response)
	err := c.cc.Invoke(ctx, "/protoInterface.Interface/Util", in, out, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

// InterfaceServer is the server API for Interface service.
// All implementations must embed UnimplementedInterfaceServer
// for forward compatibility
type InterfaceServer interface {
	// 方法1
	GetProduct(context.Context, *Request) (*Response, error)
	// 方法2
	Util(context.Context, *Request) (*Response, error)
	mustEmbedUnimplementedInterfaceServer()
}

// UnimplementedInterfaceServer must be embedded to have forward compatible implementations.
type UnimplementedInterfaceServer struct {
}

func (UnimplementedInterfaceServer) GetProduct(context.Context, *Request) (*Response, error) {
	return nil, status.Errorf(codes.Unimplemented, "method GetProduct not implemented")
}
func (UnimplementedInterfaceServer) Util(context.Context, *Request) (*Response, error) {
	return nil, status.Errorf(codes.Unimplemented, "method Util not implemented")
}
func (UnimplementedInterfaceServer) mustEmbedUnimplementedInterfaceServer() {}

// UnsafeInterfaceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to InterfaceServer will
// result in compilation errors.
type UnsafeInterfaceServer interface {
	mustEmbedUnimplementedInterfaceServer()
}

func RegisterInterfaceServer(s grpc.ServiceRegistrar, srv InterfaceServer) {
	s.RegisterService(&Interface_ServiceDesc, srv)
}

func _Interface_GetProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(Request)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(InterfaceServer).GetProduct(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: "/protoInterface.Interface/GetProduct",
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(InterfaceServer).GetProduct(ctx, req.(*Request))
	}
	return interceptor(ctx, in, info, handler)
}

func _Interface_Util_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
	in := new(Request)
	if err := dec(in); err != nil {
		return nil, err
	}
	if interceptor == nil {
		return srv.(InterfaceServer).Util(ctx, in)
	}
	info := &grpc.UnaryServerInfo{
		Server:     srv,
		FullMethod: "/protoInterface.Interface/Util",
	}
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return srv.(InterfaceServer).Util(ctx, req.(*Request))
	}
	return interceptor(ctx, in, info, handler)
}

// Interface_ServiceDesc is the grpc.ServiceDesc for Interface service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Interface_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "protoInterface.Interface",
	HandlerType: (*InterfaceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "GetProduct",
			Handler:    _Interface_GetProduct_Handler,
		},
		{
			MethodName: "Util",
			Handler:    _Interface_Util_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "build.proto",
}

同理对于方法文件也只查看核心代码,用于构建rpc服务器,映射逻辑层接口的API和构建客户端接收服务器返回值的API。如下

type InterfaceClient interface {
	// 方法1
	GetProduct(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
	// 方法2
	Util(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}

XXX_grpc.pb.go文件中一般是第一个结构体,如上述带代码是gprc接口,包含rpc服务端的所有方法。

type interfaceClient struct {
	cc grpc.ClientConnInterface
}

第二个结构体,如上述代码所示,是一个rpc客户端连接对象,表示与服务连接的实例。文件也提供了构架实例的方法,如下用于同服务端连接对象构建服务端接口,如下:

func NewInterfaceClient(cc grpc.ClientConnInterface) InterfaceClient {
	return &interfaceClient{cc}
}

通过该方法可以得到客户端的接口,通过接口调用方法。另外方法在服务器端被注册,这一样服务器注册,客户端调用,实际上就是在rpc容器内部进行。

在方法的配置文件中也存在服务器实例,如下:

// InterfaceServer is the server API for Interface service.
// All implementations must embed UnimplementedInterfaceServer
// for forward compatibility
type InterfaceServer interface {
	// 方法1
	GetProduct(context.Context, *Request) (*Response, error)
	// 方法2
	Util(context.Context, *Request) (*Response, error)
	mustEmbedUnimplementedInterfaceServer()
}

// UnimplementedInterfaceServer must be embedded to have forward compatible implementations.
type UnimplementedInterfaceServer struct {
}

这些都是通过protocol文件自动生成的,就是说通过插件生成的代码中,已经完成了方法到对应语言的数据结构如结构体或者类的生成,开发者著需要通过生成的方法构建一个服务器,将方法注册到服务器(方法需要根据逻辑重写),再创建客户端接口调用方法即可。

例如,在生成文件中,通过服务器对象构建服务器实例:

//自定义结构体继承生成的服务器类
// Server 实现服务类
type Server struct {
	protoInterface.UnimplementedInterfaceServer
}
//重写服务器端方法(继承自生成的_grpc.pb的服务器端方法)
// GetProduct
func (Server) GetProduct(context.Context, *protoInterface.Request) (*protoInterface.Response, error) {
	//获取程序中的返回值
	param := service.Product{}
	product := param.DefaultProduct()
	json := param.ToJSON(product)
	return &protoInterface.Response{
		MessageString: json,
	}, nil
}

方法是服务器端和客户端均有的,客户端的作用为接受返回值,服务器端是通过继承的方式重写方法完成一定的逻辑。这一样以来方法均存在rpc容器中,服务器和客户端均使用rpc容器调用方法,实现了跨语言性。

//构建服务器实例

// 运行服务
func main() {
	//基于tcp实现(为网络设置端口)
	listen, err := net.Listen("tcp", ":1099")
	if err != nil {
		fmt.Println("failed to listen", err)
	}
	//创建grpc服务
	server := grpc.NewServer()
	//注册自定义方法
	protoInterface.RegisterInterfaceServer(server, &Server{})
	//启动服务
	err = server.Serve(listen)
	if err != nil {
		fmt.Println("failed to serve", err)
		return
	}
}

rpc服务器grpc.NewServer(),将方法的接口注册到服务器中通过RegisterInterfaceServer方法,这也是代码生成的。至此重写的方法的接口都被注册到服务器中了。

那么该如何测试是否注册成功,或者如何调用呢?

答案是构建一个客户端调用方法,需要注意的是客户端实例是通过生成文件的_grpc.pb.文件提供的方法构建实例的,也就是说任何能调用该文件的程序都可以生成客户端实例,显然也需要请求与响应参数,也需要pb文件。

pb_grpc.pb文件复制到新项目中,构建客户端实例的代码如下:

func main() {
	//配置连连接参数(无加密)
	dial, err := grpc.Dial("localhost:1099", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		println("failed grpc connect", err)
	}
	defer dial.Close()
	//创建客户端连接
	client := protoInterface.NewInterfaceClient(dial)
	//通过客户端调用方法
	res, err := client.GetProduct(context.Background(), &protoInterface.Request{
		ParamString: "hello",
	})
	if err != nil {
		println("failed grpc recive err", err)
	}
	//打印接受的字符
	fmt.Printf("%v\n", res)

	//获取带product结构体在反序列化
	param := service.Product{}
	product := param.ToSTRUCT(res.MessageString)
	fmt.Println(product)

}

NewInterfaceClient是_grpc.pb的方法构建了一个客户端实例,客户端方法接口的所有方法都是和服务器共有的,你们服务器重写的方法注册中,客户端就可以通过实例和方法名直接调用。

如下图所示,客户端的调用直接返回了序列化的数据。

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/723702.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[ZJCTF 2019]NiZhuanSiWei1

拿到是一段php代码 <?php $text $_GET["text"]; $file $_GET["file"]; $password $_GET["password"]; if(isset($text)&&(file_get_contents($text,r)"welcome to the zjctf")){echo "<br><h1>&quo…

【高端设计】DDR4设计方法与仿真分析(一)

本文主要介绍了DDR4设计方法与仿真分析&#xff0c;并示范SIwave如何做DDR4的瞬时眼图、SSN、on-die de-cap影响、DBI耗电分析与规范性测试。 1.DDR4和DDR3的区别 1.1 DDR4传输速度与带宽增加 DDR3 1600/1866MHz -> DDR4 1866/3200MHz DDR3采用多点分支单流架构&#xff…

【电路原理学习笔记】第2章:电压、电流和电阻:2.7基本电路的测量

第2章&#xff1a;电压、电流和电阻 2.7基本电路的测量 用来测量电压的仪器是电压表&#xff0c;用来测量电流的仪器是电流表&#xff0c;用来测量电阻的仪器是欧姆表。通常&#xff0c;这3种仪器被集成到一个称为万用表的仪器中。在万用表中&#xff0c;可以通过开关选择特定…

Python接收摄像头输出的YCbYCr数据并显示图像(附Python源码)

前言 摄像头用的OV的2640&#xff0c;输出YCbYcr的十六进制数据&#xff0c;数据保存成字符串形式的hex文件&#xff0c;之后用Python读取文件&#xff0c;并显示图片。 文章先搭建Python环境&#xff0c;之后编程实现十六进制数据显示图片的功能。 十六进制文件格式如下图&am…

el-table合计样式修改,增加图片

这里的表格用的是el-table组件。如上图&#xff0c;在底部合计的两个字段上增加图片。合计用的是:summary-method"getSummaries"。增加图片的原理其实就是获取这个单元格的dom元素定位&#xff0c;然后在这个元素里面增加 img元素&#xff0c;还可以设置样式。如下图…

Django之常用组件

一、分页器组件 class Pagination(object):def __init__(self,current_page,all_count,per_page_num2,pager_count11):"""封装分页相关数据:param current_page: 当前页:param all_count: 数据库中的数据总条数:param per_page_num: 每页显示的数据条数:par…

峰会来袭 | CAD模型转换工具选择的难点和关键点解答

作为世界顶尖的3D软件开发SDK和CAD模型转换工具——HOOPS Exchange已问世十多年&#xff0c;深受开发者好评&#xff0c;并在工业测量、机械加工、造船设计等领域都有广泛的应用。 本次峰会将围绕CAD软件造型技术的多样性、CAD模型数据解析的难点、3D模型转换的经典问题等&…

曝光调整和曝光融合论文粗读

曝光调整论文调研 M. Afifi, K. G. Derpanis, B. Ommer and M. S. Brown, “Learning Multi-Scale Photo Exposure Correction,” 2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Nashville, TN, USA, 2021, pp. 9153-9163, doi: 10.1109/CVPR4…

开放式耳机什么牌子性价比好,这些高颜值蓝牙耳机分享给你

入耳式耳机在运动过程中会与耳道产生摩擦&#xff0c;产生咀嚼音、摩擦音等杂音&#xff0c;会让耳朵难受&#xff0c;听音也会受到影响&#xff0c;特别是像边看电视剧边吃零食等情况&#xff0c;会很影响体验感&#xff0c;所以开放式耳机不入耳的设计完全处理了这一问题&…

卷积神经网络| 猫狗系列【AlexNet】

首先&#xff0c;搭建网络&#xff1a; AlexNet神经网络原理图&#xff1a; net代码&#xff1a;【根据网络图来搭建网络&#xff0c;不会的看看相关视频会好理解一些】 import torchfrom torch import nnimport torch.nn.functional as Fclass MyAlexNet(nn.Module): def…

Linux系统之neofetch工具的基本使用

Linux系统之neofetch工具的基本使用 一、neofetch工具介绍1.1 neofetch简介1.2 neofetch特点 二、检查本地环境2.1 检查操作系统版本2.2 检查内核版本 三、安装neofetch工具3.1 配置yum仓库3.2 安装neofetch3.3 查看neofetch版本 四、neofetch工具的基本使用4.1 直接使用neofet…

quilt data-Working with the Catalog

Quilt Catalog 是 Quilt 的第二部分。它提供了一个在您的 S3 存储桶上的界面&#xff0c;将 Quilt 的数据包和搜索等功能带到了 Web 界面上。 请注意&#xff0c;您可以在不使用 Quilt Catalog 的情况下使用 Quilt Python API&#xff0c;但它们是设计为配合使用的。 简要介绍…

【实现openGauss5.0企业版一主一备搭建部署】

【实现openGauss5.0企业版一主一备搭建部署】 &#x1f53b; 前言&#x1f53b; 一、安装前准备&#x1f530; 1.1 openGauss安装包下载&#x1f530; 1.2 安装环境准备⛳ 1.2.1 硬件环境要求⛳ 1.2.2 软件环境要求⛳ 1.2.3 软件依赖要求⛳ 1.2.4 修改 hosts 和 hostname&#…

【react】创建启动react项目和跨域代理:

文章目录 1、创建启动react项目&#xff1a;2、跨域代理&#xff1a;【1】文档&#xff1a;[https://create-react-app.dev/docs/proxying-api-requests-in-development/](https://create-react-app.dev/docs/proxying-api-requests-in-development/)【2】src/setupProxy.js: 1…

阿姆斯特丹大学Max Welling教授-深度学习和自然科学

目录 简介 AI4Science & Science4AI 深度学习简介 AI4Science Science4AI 总结/结束语 参考 简介 人工智能一直与自然科学有着深厚的联系。 人工神经网络最初被认为是生物神经网络的抽象&#xff0c;许多后续算法&#xff08;例如强化学习&#xff09;也是如此。 神经…

springcloud actuator暴露端点漏洞修复

前段时间网络安全的同事突然通知系统漏洞&#xff0c;swagger漏洞和暴露多余端点等&#xff0c;可能会泄露信息。刚开始只是修改了相关配置。如下&#xff1a; 更改config配置 management:security:enabled: true security:user:name: xxxpassword: xxxbasic:enabled: trueen…

配置tensorflow1.15版本遇到的问题:conda环境管理/tensorflow历史版本下载/pycharm中如何使用conda中的虚拟环境

0、前言&#xff1a; 我之前在做配置环境&#xff0c;或者不懂的操作时&#xff0c;总是遇到问题在csdn或者网上搜就行了&#xff0c;然后解决问题之后&#xff0c;也不知道期间搜了哪些知识。也记不住一些修改的地方&#xff0c;这就导致&#xff0c;我十分担心好不容易搭好的…

spring系列-SpringCloud

SpringCloud概述 微服务概述 什么是微服务 目前的微服务并没有一个统一的标准&#xff0c;一般是以业务来划分 将传统的一站式应用&#xff0c;拆分成一个个的服务&#xff0c;彻底去耦合&#xff0c;一个微服务就是单功能业务&#xff0c;只做一件事。 与微服务相对的叫巨石 …

“提高个人生产力:思维导图在时间管理和计划中的应用“

在高效成为当今时代职场人高频谈论的一个词后&#xff0c;时间管理和计划的重要性也日渐显现。一个好的时间管理和计划可以在不知不觉中有效帮助我们更加合理的安排时间&#xff0c;保证工作的有序进行和按时完成。通过合理的协调工作与休息之间的关系&#xff0c;避免我们浪费…

15、服务端实战:数据库工具封装

在了解完 NestJS 的基础配置之后&#xff0c;服务端的内容将引来一个比较重要的环节&#xff1a;数据库。 因为数据库的内容比较多&#xff0c;所以相关内容将分为两个章节来展开讨论&#xff1a; 数据库工具封装 - 将封装统一的数据库操作工具类&#xff0c;方便后期开发于集…