公司网站建设行为规定网站加载速度慢的原因
- 作者: 五速梦信息网
- 时间: 2026年03月21日 11:08
当前位置: 首页 > news >正文
公司网站建设行为规定,网站加载速度慢的原因,竞拍网站模板,网站后台多个管理员背景 之前做过一个前端低代码编辑平台#xff0c;可以实现简单的移动端页面组件拖拽编辑#xff1a; https://github.com/li-car-fei/react-visual-design 最近基于C的oatpp框架实现了一下后台。使用oatpp框架做web后台开发时#xff0c;发现按照官方的示例使用的话#…背景 之前做过一个前端低代码编辑平台可以实现简单的移动端页面组件拖拽编辑 https://github.com/li-car-fei/react-visual-design 最近基于C的oatpp框架实现了一下后台。使用oatpp框架做web后台开发时发现按照官方的示例使用的话很难在多表多控制视图模式下进行开发因此修改了一些它的使用方法以面向对象的方式对各个部分管理高效开发。 github链接https://github.com/li-car-fei/oatpp-low-code 求求 star~~ 其中对于低代码平台中核心功能实现思路如下所述。 主要思路 运用 oatpp 搭建后端服务程序 Restful API 接口 (Swagger 提供接口示例文档) 将低代码的逻辑通过四个表实现 user 表用户信息一个用户对应多个projectproject 表某个低代码编辑图的基础信息一个project对应多个componentcomponent 表组件表储存组件类别、属性、序号等一个component对应0个或多个childComponnetchildComponent 表子组件表存储子组件属性、序号等 对 oatpp CRUD 的改写 数据 DTO 有共用字段的采用类的继承方式定义 /**
- 组件记录的 DTO */ class ComponentRecordDto : public oatpp::DTO {DTO_INIT(ComponentRecordDto, DTO)DTO_FIELD(Int32, record_id);DTO_FIELD(Int32, project_id, project_id);DTO_FIELD(EnumComponentType::AsString, component_type);DTO_FIELD(Int32, components_index);DTO_FIELD(String, currentDate);DTO_FIELD(String, header, header);DTO_FIELD(String, title, title);DTO_FIELD(String, content, content);DTO_FIELD(String, mode, mode);DTO_FIELD(String, src, src);DTO_FIELD(String, link, link);DTO_FIELD(String, label1, label1);DTO_FIELD(String, label2, label2);DTO_FIELD(String, backgroundColor, backgroundColor); };/**
- 组件记录 包括了子组件数组 数据 的 DTO
/
class ComponentTransferDto : public ComponentRecordDto {DTO_INIT(ComponentTransferDto, ComponentRecordDto)DTO_FIELD(Vectoroatpp::ObjectChildComponentTranserDto, childs, childs);
};Db 部分每个表的SQL操作分别定义为一个类随后挂载到一个总的 Db 类中使用共享的数据库连接池和语句执行器excuator
/** 总的 DB 类管理所有的 数据相关操作类
/
class Db {
public:Db(const std::shared_ptroatpp::orm::Executor executor): userDb(std::make_sharedUserDb(executor)),projectDb(std::make_sharedProjectDb(executor)),componentDb(std::make_sharedComponentDb(executor)),childComponentDb(std::make_sharedChildComponentDb(executor)){std::cout Db start creating std::endl;oatpp::orm::SchemaMigration migration(executor);migration.addFile(1 / start from version 1 /, DATABASE_MIGRATIONS /001_init.sql);// TODO - Add more migrations here.migration.migrate(); // – run migrations. This guy will throw on error.auto version executor-getSchemaVersion();OATPP_LOGD(Db, Migration - OK. Version%lld., version);};std::shared_ptrUserDb userDb;std::shared_ptrProjectDb projectDb;std::shared_ptrComponentDb componentDb;std::shared_ptrChildComponentDb childComponentDb;
};service 方面 定义一个基础服务类存储 Db 与所有服务共用的成员 每个表的服务定义一个service虚继承基础服务类保证后续派生类只有一个Db连接提供每个表自己独立的服务 所有的 service都继承自基础服务类即共用一个数据库连接池共用一套集成好的 SQL 语句接口 两个表相关的服务且有层次关系的如组件和子组件则采用继承方式实现使得组件服务可以调用子组件服务 多个表相关的服务如整个 project 相关的服务另外新建一个 service 类继承所需的服务对应的类实现 只需直接继承 BaseService 的类是虚继承即可就可保证所有类中只有一份 Db
/** BaseService* 声明 Status 后续子类都用于HTTP状态的码的设定* 保存 std::shared_ptrDb m_database用于数据库相关操作* 直接继承BaseService的类需要是 virtual 继承则可保证所有相关Service类中都只有一份Db / class BaseService {/ protected 子类可以访问到外界不可以访问 /protected:typedef oatpp::web::protocol::http::Status Status;std::shared_ptrDb m_database;public:BaseService(std::shared_ptrDb database) : m_database(database) {}; };/ 子组件相关服务 / class ChildComponentService : virtual public BaseService {public:ChildComponentService(std::shared_ptrDb database) : BaseService(database) {};/ others… / };/ 组件相关服务 / class ComponentService : public ChildComponentService {public:/** 虚继承中需要由最上层派生类调用基类的构造函数* (普通继承则不用调用直接继承的基类的构造即可)/ComponentService(std::shared_ptrDb database) : BaseService(database), ChildComponentService(database) {};/ others… / }; controller 方面与 service 提供的服务对应起来定义HTTP接口的信息 每个 controller 都接收指向 Db 的共享指针以传给对应的 service 成员 controller 继承自 oatpp 提供的对象需要从环境中找到序列化/反序列化器objectMapper用于其初始化 定义一个将所有controller进行统一管理的 MyController将所有实例只需一个挂载到里面并对外提供统一的controller相关操作接口如router配置
/** 通过一个 MyController 将所有的 数据库相关的 Controller 包含起来* 统一完成 原本在App.cpp 中的 路由的配置 /class MyController {public:/ 构造函数 一个database对象构建所有 Controller /MyController(std::shared_ptrDb database) : userController(UserController::createShared(database)),projectController(ProjectController::createShared(database)),componentController(ComponentController::createShared(database)),childComponentController(ChildComponentController::createShared(database)),uploadController(UploadController::createShared()){};/ 静态函数MyController 只需要一个实例即可 /static std::shared_ptrMyController createShared(std::shared_ptrDb database){return std::make_sharedMyController(database);}/ 通过 MyController 完成 所有 子Controller 的路由配置 /void setRouter(oatpp::web::server::api::Endpoints docEndpoints,std::shared_ptroatpp::web::server::HttpRouter router){docEndpoints.append(router-addController(userController)-getEndpoints());docEndpoints.append(router-addController(projectController)-getEndpoints());docEndpoints.append(router-addController(componentController)-getEndpoints());docEndpoints.append(router-addController(childComponentController)-getEndpoints());docEndpoints.append(router-addController(uploadController)-getEndpoints());};/ 所有的 Controller */std::shared_ptrUserController userController;std::shared_ptrProjectController projectController;std::shared_ptrComponentController componentController;std::shared_ptrChildComponentController childComponentController;std::shared_ptrUploadController uploadController; };另外运用oatpp的文件上传接口提供图片上传用于AI模型识别识别后调用projectComplete的服务存储完整低代码视图信息 ENDPOINT_INFO(upload) {info-summary upload image to parse;} ENDPOINT(POST, /upload, upload, REQUEST(std::shared_ptrIncomingRequest, request)) {oatpp::data::stream::FileOutputStream fileOutputStream(UPLOADFILEPATH);request-transferBodyToStream(fileOutputStream); // transfer body chunk by chunkreturn createResponse(Status::CODE200, OK); }Interceptor Auth 鉴权 JWT 模式对 header 中的 json web token userId 进行加解密确认 AuthController 中配置哪些接口不需要鉴权其余的接口都要增加 JWT 的 Header 参数设置 请求接口接收后需要 Interceptor 模式进行加解密确认 接口示例
- 上一篇: 公司网站建设系统专题网站开发工具
- 下一篇: 公司网站建设须知网站cms系统排名
相关文章
-
公司网站建设系统专题网站开发工具
公司网站建设系统专题网站开发工具
- 技术栈
- 2026年03月21日
-
公司网站建设西安做网站论坛 前置许可
公司网站建设西安做网站论坛 前置许可
- 技术栈
- 2026年03月21日
-
公司网站建设推荐q479185700顶上搜索引擎营销的方法有哪些
公司网站建设推荐q479185700顶上搜索引擎营销的方法有哪些
- 技术栈
- 2026年03月21日
-
公司网站建设须知网站cms系统排名
公司网站建设须知网站cms系统排名
- 技术栈
- 2026年03月21日
-
公司网站建设需推广远大科技 网站建设
公司网站建设需推广远大科技 网站建设
- 技术栈
- 2026年03月21日
-
公司网站建设应注意哪些wordpress 编辑模板下载
公司网站建设应注意哪些wordpress 编辑模板下载
- 技术栈
- 2026年03月21日

