基于libevent的多线程http server (CentOS)

文章目录

      • 一、安装libevent
      • 二、安装jsoncpp
      • 三、http多线程服务

一、安装libevent

下载编译安装,提前安装好gcc, make

sudo su
yum -y install wget
wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz
tar -zxvf libevent-2.0.10-stable.tar.gz
cd libevent-2.0.10-stable
./configure --prefix=/usr
make -j2
make install# 查看安装结果
ls -al /usr/lib | grep libevent

安装后的输出信息,

make  install-recursive
make[1]: Entering directory `/home/username/libevent-2.0.10-stable'
Making install in .
make[2]: Entering directory `/home/username/libevent-2.0.10-stable'
make[3]: Entering directory `/home/username/libevent-2.0.10-stable'
test -z "/usr/bin" || /usr/bin/mkdir -p "/usr/bin"/usr/bin/install -c event_rpcgen.py '/usr/bin'
test -z "/usr/lib" || /usr/bin/mkdir -p "/usr/lib"/bin/sh ./libtool   --mode=install /usr/bin/install -c   libevent.la libevent_core.la libevent_extra.la libevent_pthreads.la libevent_openssl.la '/usr/lib'
libtool: install: /usr/bin/install -c .libs/libevent-2.0.so.5.0.1 /usr/lib/libevent-2.0.so.5.0.1
libtool: install: (cd /usr/lib && { ln -s -f libevent-2.0.so.5.0.1 libevent-2.0.so.5 || { rm -f libevent-2.0.so.5 && ln -s libevent-2.0.so.5.0.1 libevent-2.0.so.5; }; })
libtool: install: (cd /usr/lib && { ln -s -f libevent-2.0.so.5.0.1 libevent.so || { rm -f libevent.so && ln -s libevent-2.0.so.5.0.1 libevent.so; }; })
libtool: install: /usr/bin/install -c .libs/libevent.lai /usr/lib/libevent.la
libtool: install: /usr/bin/install -c .libs/libevent_core-2.0.so.5.0.1 /usr/lib/libevent_core-2.0.so.5.0.1
libtool: install: (cd /usr/lib && { ln -s -f libevent_core-2.0.so.5.0.1 libevent_core-2.0.so.5 || { rm -f libevent_core-2.0.so.5 && ln -s libevent_core-2.0.so.5.0.1 libevent_core-2.0.so.5; }; })
libtool: install: (cd /usr/lib && { ln -s -f libevent_core-2.0.so.5.0.1 libevent_core.so || { rm -f libevent_core.so && ln -s libevent_core-2.0.so.5.0.1 libevent_core.so; }; })
libtool: install: /usr/bin/install -c .libs/libevent_core.lai /usr/lib/libevent_core.la
libtool: install: /usr/bin/install -c .libs/libevent_extra-2.0.so.5.0.1 /usr/lib/libevent_extra-2.0.so.5.0.1
libtool: install: (cd /usr/lib && { ln -s -f libevent_extra-2.0.so.5.0.1 libevent_extra-2.0.so.5 || { rm -f libevent_extra-2.0.so.5 && ln -s libevent_extra-2.0.so.5.0.1 libevent_extra-2.0.so.5; }; })
libtool: install: (cd /usr/lib && { ln -s -f libevent_extra-2.0.so.5.0.1 libevent_extra.so || { rm -f libevent_extra.so && ln -s libevent_extra-2.0.so.5.0.1 libevent_extra.so; }; })
libtool: install: /usr/bin/install -c .libs/libevent_extra.lai /usr/lib/libevent_extra.la
libtool: install: /usr/bin/install -c .libs/libevent_pthreads-2.0.so.5.0.1 /usr/lib/libevent_pthreads-2.0.so.5.0.1
libtool: install: (cd /usr/lib && { ln -s -f libevent_pthreads-2.0.so.5.0.1 libevent_pthreads-2.0.so.5 || { rm -f libevent_pthreads-2.0.so.5 && ln -s libevent_pthreads-2.0.so.5.0.1 libevent_pthreads-2.0.so.5; }; })
libtool: install: (cd /usr/lib && { ln -s -f libevent_pthreads-2.0.so.5.0.1 libevent_pthreads.so || { rm -f libevent_pthreads.so && ln -s libevent_pthreads-2.0.so.5.0.1 libevent_pthreads.so; }; })
libtool: install: /usr/bin/install -c .libs/libevent_pthreads.lai /usr/lib/libevent_pthreads.la
libtool: install: /usr/bin/install -c .libs/libevent_openssl-2.0.so.5.0.1 /usr/lib/libevent_openssl-2.0.so.5.0.1
libtool: install: (cd /usr/lib && { ln -s -f libevent_openssl-2.0.so.5.0.1 libevent_openssl-2.0.so.5 || { rm -f libevent_openssl-2.0.so.5 && ln -s libevent_openssl-2.0.so.5.0.1 libevent_openssl-2.0.so.5; }; })
libtool: install: (cd /usr/lib && { ln -s -f libevent_openssl-2.0.so.5.0.1 libevent_openssl.so || { rm -f libevent_openssl.so && ln -s libevent_openssl-2.0.so.5.0.1 libevent_openssl.so; }; })
libtool: install: /usr/bin/install -c .libs/libevent_openssl.lai /usr/lib/libevent_openssl.la
libtool: install: /usr/bin/install -c .libs/libevent.a /usr/lib/libevent.a
libtool: install: chmod 644 /usr/lib/libevent.a
libtool: install: ranlib /usr/lib/libevent.a
libtool: install: /usr/bin/install -c .libs/libevent_core.a /usr/lib/libevent_core.a
libtool: install: chmod 644 /usr/lib/libevent_core.a
libtool: install: ranlib /usr/lib/libevent_core.a
libtool: install: /usr/bin/install -c .libs/libevent_extra.a /usr/lib/libevent_extra.a
libtool: install: chmod 644 /usr/lib/libevent_extra.a
libtool: install: ranlib /usr/lib/libevent_extra.a
libtool: install: /usr/bin/install -c .libs/libevent_pthreads.a /usr/lib/libevent_pthreads.a
libtool: install: chmod 644 /usr/lib/libevent_pthreads.a
libtool: install: ranlib /usr/lib/libevent_pthreads.a
libtool: install: /usr/bin/install -c .libs/libevent_openssl.a /usr/lib/libevent_openssl.a
libtool: install: chmod 644 /usr/lib/libevent_openssl.a
libtool: install: ranlib /usr/lib/libevent_openssl.a
libtool: finish: PATH="/opt/rh/devtoolset-8/root/usr/bin:/home/username/cmake-3.23.4-linux-x86_64/bin:/opt/rh/devtoolset-8/root/usr/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/username/.local/bin:/home/username/bin:/sbin" ldconfig -n /usr/lib
----------------------------------------------------------------------
Libraries have been installed in:/usr/libIf you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:- add LIBDIR to the `LD_LIBRARY_PATH' environment variableduring execution- add LIBDIR to the `LD_RUN_PATH' environment variableduring linking- use the `-Wl,-rpath -Wl,LIBDIR' linker flag- have your system administrator add LIBDIR to `/etc/ld.so.conf'See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
[username@localhost libevent-2.0.10-stable]$ ls -al /usr/lib | grep libevent
lrwxrwxrwx.  1 root root      21 Jul 26 13:26 libevent-2.0.so.5 -> libevent-2.0.so.5.0.1
-rwxr-xr-x.  1 root root 1246224 Jul 26 13:26 libevent-2.0.so.5.0.1
-rw-r--r--.  1 root root 2204618 Jul 26 13:26 libevent.a
lrwxrwxrwx.  1 root root      26 Jul 26 13:26 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.0.1
-rwxr-xr-x.  1 root root  770744 Jul 26 13:26 libevent_core-2.0.so.5.0.1
-rw-r--r--.  1 root root 1323706 Jul 26 13:26 libevent_core.a
-rwxr-xr-x.  1 root root     975 Jul 26 13:26 libevent_core.la
lrwxrwxrwx.  1 root root      26 Jul 26 13:26 libevent_core.so -> libevent_core-2.0.so.5.0.1
lrwxrwxrwx.  1 root root      27 Jul 26 13:26 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.0.1
-rwxr-xr-x.  1 root root  501664 Jul 26 13:26 libevent_extra-2.0.so.5.0.1
-rw-r--r--.  1 root root  880986 Jul 26 13:26 libevent_extra.a
-rwxr-xr-x.  1 root root     982 Jul 26 13:26 libevent_extra.la
lrwxrwxrwx.  1 root root      27 Jul 26 13:26 libevent_extra.so -> libevent_extra-2.0.so.5.0.1
-rwxr-xr-x.  1 root root     940 Jul 26 13:26 libevent.la
lrwxrwxrwx.  1 root root      29 Jul 26 13:26 libevent_openssl-2.0.so.5 -> libevent_openssl-2.0.so.5.0.1
-rwxr-xr-x.  1 root root  117392 Jul 26 13:26 libevent_openssl-2.0.so.5.0.1
-rw-r--r--.  1 root root  217556 Jul 26 13:26 libevent_openssl.a
-rwxr-xr-x.  1 root root    1011 Jul 26 13:26 libevent_openssl.la
lrwxrwxrwx.  1 root root      29 Jul 26 13:26 libevent_openssl.so -> libevent_openssl-2.0.so.5.0.1
lrwxrwxrwx.  1 root root      30 Jul 26 13:26 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.0.1
-rwxr-xr-x.  1 root root   26440 Jul 26 13:26 libevent_pthreads-2.0.so.5.0.1
-rw-r--r--.  1 root root   26454 Jul 26 13:26 libevent_pthreads.a
-rwxr-xr-x.  1 root root    1003 Jul 26 13:26 libevent_pthreads.la
lrwxrwxrwx.  1 root root      30 Jul 26 13:26 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.0.1
lrwxrwxrwx.  1 root root      21 Jul 26 13:26 libevent.so -> libevent-2.0.so.5.0.1

二、安装jsoncpp

开源地址:https://github.com/open-source-parsers/jsoncpp

wget https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.4.tar.gz
tar -zxvf 1.9.4.tar.gz
cd jsoncpp-1.9.4/
mkdir build && cd build/cmake -DCMAKE_BUILD_TYPE=release \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_INCLUDEDIR=/usr/include/jsoncpp \
-DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../make -j2
sudo make install
[username@localhost build]$ sudo make install
[sudo] password for username:
Consolidate compiler generated dependencies of target jsoncpp_lib
[ 23%] Built target jsoncpp_lib
Consolidate compiler generated dependencies of target jsoncpp_static
[ 47%] Built target jsoncpp_static
Consolidate compiler generated dependencies of target jsoncpp_object
[ 64%] Built target jsoncpp_object
Consolidate compiler generated dependencies of target jsontestrunner_exe
[ 76%] Built target jsontestrunner_exe
Consolidate compiler generated dependencies of target jsoncpp_test
[100%] Built target jsoncpp_test
Install the project...
-- Install configuration: "release"
-- Installing: /usr/local/lib64/pkgconfig/jsoncpp.pc
-- Installing: /usr/local/lib64/cmake/jsoncpp/jsoncppConfig.cmake
-- Installing: /usr/local/lib64/cmake/jsoncpp/jsoncppConfig-release.cmake
-- Installing: /usr/local/lib64/cmake/jsoncpp/jsoncppConfigVersion.cmake
-- Installing: /usr/local/lib64/libjsoncpp.so.1.9.4
-- Installing: /usr/local/lib64/libjsoncpp.so.24
-- Installing: /usr/local/lib64/libjsoncpp.so
-- Installing: /usr/local/lib64/libjsoncpp_static.a
-- Installing: /usr/local/lib64/objects-release/jsoncpp_object/json_reader.cpp.o
-- Installing: /usr/local/lib64/objects-release/jsoncpp_object/json_value.cpp.o
-- Installing: /usr/local/lib64/objects-release/jsoncpp_object/json_writer.cpp.o
-- Installing: /usr/include/jsoncpp/json/allocator.h
-- Installing: /usr/include/jsoncpp/json/assertions.h
-- Installing: /usr/include/jsoncpp/json/config.h
-- Installing: /usr/include/jsoncpp/json/forwards.h
-- Installing: /usr/include/jsoncpp/json/json.h
-- Installing: /usr/include/jsoncpp/json/json_features.h
-- Installing: /usr/include/jsoncpp/json/reader.h
-- Installing: /usr/include/jsoncpp/json/value.h
-- Installing: /usr/include/jsoncpp/json/version.h
-- Installing: /usr/include/jsoncpp/json/writer.h

配置库目录
vim ~/.bashrc

export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH

source ~/.bashrc

三、http多线程服务

#pragma once#include <event.h>
#include <evhttp.h>
#include <pthread.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <iostream>
#include <thread>
#include <vector>
#include <functional>
#include <list>#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <cstdlib>
#include <jsoncpp/json/json.h>using namespace std;#define LOG_DBG   printf
#define LOG_INFO  printf
#define LOG_WARN  printf
#define LOG_ERR   printfnamespace servers
{
class HttpSrv
{
public:HttpSrv() {}~HttpSrv() {}bool start(int port, int nthreads);bool stop();protected:struct WorkRoom {HttpSrv* pSrv;struct event_base* base;struct evhttp* httpd;struct event* watchdogEv;bool dispatchStop = false;};list<WorkRoom*> workRoomList;vector<thread> mWorkThList;bool mIsExit = false;static void watchdog(int fd, short event, void* argv);void Dispatch(void* arg);static void GenericHandler(struct evhttp_request* req, void* arg);static void ProcessRequest(struct evhttp_request* request, void* arg);static void HandlePostRequest(struct evhttp_request* request, void* arg);int BindSocket(int port);
};int HttpSrv::BindSocket(int port)
{int r;int nfd;nfd = socket(AF_INET, SOCK_STREAM, 0);if (nfd < 0) return -1;int one = 1;r = setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(int));struct sockaddr_in addr;memset(&addr, 0, sizeof(addr));addr.sin_family = AF_INET;addr.sin_addr.s_addr = INADDR_ANY;addr.sin_port = htons(port);r = bind(nfd, (struct sockaddr*)&addr, sizeof(addr));if (r < 0) return -1;r = listen(nfd, 10240);if (r < 0) return -1;int flags;if ((flags = fcntl(nfd, F_GETFL, 0)) < 0 || fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) return -1;return nfd;
}bool HttpSrv::start(int port, int nthreads) {int r;int nfd = BindSocket(port);//监听端口if (nfd < 0) return false;for (int i = 0; i < nthreads; i++){WorkRoom* w = new WorkRoom;//每个线程独有的环境参数,不使用局部变量,防止离开局部作用域后失效w->pSrv = this;w->base = event_init();    //libevnet使用多线程,每个线程中使用一个baseif (w->base == NULL) return false;w->httpd = evhttp_new(w->base);//初始化httpif (w->httpd == NULL) return false;r = evhttp_accept_socket(w->httpd, nfd);if (r != 0) return false;evhttp_set_gencb(w->httpd, GenericHandler, this);       //设置http路由 404evhttp_set_cb(w->httpd, "/test", ProcessRequest, this); //设置http路由evhttp_set_cb(w->httpd, "/image", HandlePostRequest, this); //设置http路由struct timeval tv;tv.tv_sec = 1;tv.tv_usec = 0;event* watchdogEv = event_new(w->base, -1, EV_PERSIST | EV_TIMEOUT, watchdog, w);//每个base设置一个看门狗,可以做一些线程监控的工作w->watchdogEv = watchdogEv;event_add(watchdogEv, &tv);mWorkThList.push_back(std::thread(std::bind(&HttpSrv::Dispatch, this, std::placeholders::_1), w)); //启动事件分发workRoomList.push_back(w);//线程环境变量收集,善后处理}LOG_INFO("http start port:%d, thNum:%d\n", port, nthreads);return true;
}bool HttpSrv::stop() {mIsExit = true;while (workRoomList.size() > 0) {for (auto w : workRoomList) {if (!w->dispatchStop) {continue;}if (w->watchdogEv) {event_free(w->watchdogEv);w->watchdogEv = nullptr;}if (w->httpd) {evhttp_free(w->httpd);w->httpd = nullptr;}if (w->base) {event_base_free(w->base);w->base = nullptr;}workRoomList.remove(w);delete w;break;}}for (auto& t : mWorkThList) {if (t.joinable()) {t.join();}}return true;
}void HttpSrv::Dispatch(void* arg) {LOG_DBG("dispatch start\n");WorkRoom* w = (WorkRoom*)arg;event_base_dispatch(w->base);LOG_DBG("dispatch stop\n");w->dispatchStop = true;
}void HttpSrv::watchdog(int fd, short event, void* argv) {WorkRoom* w = (WorkRoom*)argv;HttpSrv* pSrv = w->pSrv;if (pSrv->mIsExit) {struct timeval delay = { 0, 1 };event_base_loopexit(w->base, &delay);}
}void HttpSrv::GenericHandler(struct evhttp_request* req, void* arg)
{((HttpSrv*)arg)->ProcessRequest(req, arg);
}void HttpSrv::ProcessRequest(struct evhttp_request* req, void* arg)
{// sleep(1);struct evbuffer* buf = evbuffer_new();if (buf == NULL)return;evbuffer_add_printf(buf, "Requested: %s\n", evhttp_request_uri(req));evhttp_send_reply(req, HTTP_OK, "OK", buf);
}void HttpSrv::HandlePostRequest(struct evhttp_request* req, void* arg)
{// Get URIconst char* uri = evhttp_request_uri(req);// Parse URIstruct evkeyvalq params;evhttp_parse_query(uri, &params);// Get parametersconst char* key = evhttp_find_header(&params, "key");const char* key2 = evhttp_find_header(&params, "key2");// Check if parameters are presentif (key != NULL) {// Process key// ...return;}if (key2 != NULL) {// Process key2// ...return;}size_t len = evbuffer_get_length(req->input_buffer);char* data = (char*)malloc(len);evbuffer_remove(req->input_buffer, data, len);Json::Reader reader;Json::Value json;if (!reader.parse(data, json)) {// Handle errorreturn;}// Process JSON data// ...// Create responseJson::Value response;response["status"] = "success";Json::FastWriter writer;std::string output = writer.write(response);struct evbuffer* buf = evbuffer_new();evbuffer_add(buf, output.c_str(), output.size());evhttp_send_reply(req, HTTP_OK, "OK", buf);free(data);
}}int main()
{servers::HttpSrv s;s.start(8080, 5);sleep(60);LOG_INFO("http to stop\n");s.stop();LOG_INFO("http stop\n");}

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

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

相关文章

小白到运维工程师自学之路 第六十集 (docker的概述与安装)

一、概述 1、客户&#xff08;老板&#xff09;-产品-开发-测试-运维项目周期不断延后&#xff0c;项目质量差。 随着云计算和DevOps生态圈的蓬勃发展&#xff0c;产生了大量优秀的系统和软件。软件开发人员可以自由选择各种软件应用环境。但同时带来的问题就是需要维护一个非…

React高阶学习(二)

目录 1. 基本概念和语法2. 组件化开发3. 状态管理4. 生命周期钩子5. 条件渲染6. 循环渲染7. 事件处理8. 组件间通信9. 动画效果10. 模块化开发 1. 基本概念和语法 React 是基于 JavaScript 的库&#xff0c;用于构建用户界面。它采用虚拟 DOM 技术&#xff0c;能够高效地渲染页…

spring-authorization-server (1.1.1)自定义认证

前言 注意&#xff1a;我本地没有生成公钥和私钥&#xff0c;所以每次启动项目jwkSource都会重新生成&#xff0c;导致之前认证的token都会失效&#xff0c;具体如何生成私钥和公钥以及怎么配置到授权服务器中&#xff0c;网上有很多方法自行实现即可 之前有个项目用的0.0.3的…

Vue(待续)

概念 一套用于构建用户界面的渐进式JavaScript框架 Vue可以自底向上逐层的应用&#xff1a; 简单应用:只需一个轻量小巧的核心库。 复杂应用:可以引入各式各样的Vue插件。 1.采用组件化模式&#xff0c;提高代码复用率、且让代码更好维护。 2.声明式编码&#xff0c;让编码人员…

【设计模式——学习笔记】23种设计模式——装饰器模式Decorator(原理讲解+应用场景介绍+案例介绍+Java代码实现)

文章目录 生活案例咖啡厅 咖啡定制案例 装饰者模式介绍介绍出场角色 案例实现案例一&#xff08;咖啡厅问题&#xff09;类图代码实现咖啡样式拓展代码实现 案例二类图代码实现 装饰着模式在IO流源码的应用总结什么是父类和子类的一致性如何让自己和被委托对象有一致性 文章说明…

深度学习和神经网络

人工神经网络分为两个阶段&#xff1a; 1 &#xff1a;接收来自其他n个神经元传递过来的信号&#xff0c;这些输入信号通过与相应的权重进行 加权求和传递给下个阶段。&#xff08;预激活阶段&#xff09; 2&#xff1a;把预激活的加权结果传递给激活函数 sum :加权 f:激活…

【Linux】UDP协议

​&#x1f320; 作者&#xff1a;阿亮joy. &#x1f386;专栏&#xff1a;《学会Linux》 &#x1f387; 座右铭&#xff1a;每个优秀的人都有一段沉默的时光&#xff0c;那段时光是付出了很多努力却得不到结果的日子&#xff0c;我们把它叫做扎根 目录 &#x1f449;传输层&a…

初级算法-动态规划

文章目录 爬楼梯题意&#xff1a;解&#xff1a;代码&#xff1a; 买卖股票的最佳时机题意&#xff1a;解&#xff1a;代码&#xff1a; 最大子序和题意&#xff1a;解&#xff1a;代码&#xff1a; 打家劫舍题意&#xff1a;解&#xff1a;代码&#xff1a; 爬楼梯 题意&…

Mysql的锁

加锁的目的 对数据加锁是为了解决事务的隔离性问题&#xff0c;让事务之前相互不影响&#xff0c;每个事务进行操作的时候都必须先加上一把锁&#xff0c;防止其他事务同时操作数据。 事务的属性 &#xff08;ACID&#xff09; 原子性 一致性 隔离性 持久性 事务的隔离级别 锁…

(3)Gymnasium--CartPole的测试基于DQN

1、使用Pytorch基于DQN的实现 1.1 主要参考 (1)推荐pytorch官方的教程 Reinforcement Learning (DQN) Tutorial — PyTorch Tutorials 2.0.1cu117 documentation (2) Pytorch 深度强化学习 – CartPole问题|极客笔记 2.2 pytorch官方的教程原理 待续&#xff0c;这两天时…

bug篇之基于docker安装nacos(2.1.1)使用dubbo连接不上的问题

说明&#xff1a;首先我的nacos安装是2.1.1版本&#xff0c;请注意版本问题。另外启动时用dubbo的话必须先启动服务提供者再启动服务使用者&#xff0c;否则会报错&#xff0c;同时也必须开放三个端口&#xff1a;8848&#xff0c;9848&#xff0c;9849 java.lang.IllegalStat…

Python入门【__init__ 构造方法和 __new__ 方法、类对象、类属性、类方法、静态方法、内存分析实例对象和类对象创建过程(重要)】(十四)

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是爱敲代码的小王&#xff0c;CSDN博客博主,Python小白 &#x1f4d5;系列专栏&#xff1a;python入门到实战、Python爬虫开发、Python办公自动化、Python数据分析、Python前后端开发 &#x1f4e7;如果文章知识点有错误…

防止表单的重复提交

思想 打开页面时&#xff0c;生成一个token&#xff0c;将这个token保存到Session中&#xff0c;在表单中提供一个隐藏域&#xff0c;设置其值为每1步中生成的token在处理表单的Servlet中&#xff0c;获取表单隐藏域中的token与Session中的token进行比较&#xff0c;比较完之后…

设计模式——简单工厂模式

1 概述 将创造对象的工作交给一个单独的类来实现 &#xff0c;这个单独的类就是工厂。 2 实现 假设要做一个计算器的需求&#xff0c;通常我们想到的是这样写&#xff1a; package com.example.easyfactory;import java.util.Scanner;public class Demo1 {public static vo…

spring学习笔记十五

Spring整合Mybatis 1、导入pom坐标 <dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.16</version></dependency><!-- https://mvnrepository.com/artifact/c3p0/c3p0 --><!…

SpringBoot Jackson 日期格式化统一配置

目录 1.在全局配置文件配置 2.通过JavaBean方式配置 1.在全局配置文件配置 spring:jackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT8 该配置方式仅支持 Date 类型的日期格式化&#xff0c;不支持LocalDate 及 LocalDateTime 的格式化。 2.通过JavaBean方式配置 …

[C++] 类与对象(上)

目录 1、前言 2、类的引入 3、类的定义 3.1 类的两种定义方式 4、类的访问限定符 5、类的作用域 6、类的实例化 7、类对象模型 7.1 内存对齐规则 7.1 类对象的存储方式 8、this指针 8.1 this指针的特性 8.2 this指针是否可以为空 1、前言 C语言是面向过程的&#…

DUBBO服务多网卡,服务调用失败

如果服务器是多网卡的&#xff0c;比如安装了docker&#xff0c;有一个docker虚拟网卡&#xff0c;一个实体网卡eth0&#xff0c;当我们运行springboot应用后&#xff0c;dubbo注入到zk的地址是 docker虚拟网卡的地址172网段&#xff0c;而不是实际内网地址192网段&#xff0c;…

类的封装和包(JAVA)

封装 所有的OOP语言都会有三个特征&#xff1a; 封装&#xff1b;继承&#xff1b;多态。 本篇文章会为大家带来有关封装的知识。 在我们日常生活中可以看到电视就只有那么几个按键&#xff08;开关&#xff0c;菜单……&#xff09;和一些接口&#xff0c;而而我们通过这些东…

【计算机视觉|人脸建模】SOFA:基于风格、由单一示例的2D关键点驱动的3D面部动画

本系列博文为深度学习/计算机视觉论文笔记&#xff0c;转载请注明出处 标题&#xff1a;SOFA: Style-based One-shot 3D Facial Animation Driven by 2D landmarks 链接&#xff1a;SOFA: Style-based One-shot 3D Facial Animation Driven by 2D landmarks | Proceedings of …