# great **Repository Path**: LingfeiKeji/great ## Basic Information - **Project Name**: great - **Description**: 这个真好,Pass框架,基于Grovy做动态的实现 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2020-02-26 - **Last Updated**: 2025-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 愿景 - 成为低代码开发平台. - 全权管理,所有组件化代码,统一底层和工具类代码. - 动态修改代码,直接线上编程,无需启停项目就能更新. - 可以支持一个端口,多个系统,多套配置,系统级多租户(多配置)。 - DDD设计模式的实现: - 可以支持单机、集群、SOA、微服务、分布式等切换,而不需要修改接口实现类代码。 - 以组件为划分技术层级的功能. # 原理 - 将所有技术模块拆分成组件,类似spring-boot中的starter > 不同的是,每个组件必须要提供 单机、集群、SOA、微服务、分布式 的适配方式。 - 用context(map)代替各种PO、VO、DTO、BO、POJO、BO/DO - 参数传递全部用context - 没有结构上的dao,service,component,controller严格分层. > 取而代之的是, domain概念。 即只完成某一领域的功能。 - 利用实时编译grovy,实现动态修改代码...等功能. # 运行流程图 ![great运行流程图.png](https://gitee.com/sxran/great/raw/master/great-doc/drawio/great运行流程图.png) # 系统结构图 ![great系统结构图.png](https://gitee.com/sxran/great/raw/master/great-doc/drawio/great系统结构图.png) # 术语 - 组件: 实现某一技术功能的: 如jdbc - 基础服务: 实现某些基本的业务场景(和业务场景分离): 如 阿里云OSS, - 业务服务: 实现具体的业务场景. - domain: 是指【DDD】领域驱动设计实践 —— Domain层实现 > DDD 中有很多层的分类,这些只要再组件层把他适配就行了。 - 调试: 是指对great框架内核流程和组件的调试 - 开发: 是指开发某个domain功能. - 驱动配置: 针对great框架核心流程配置项的统称。 - common: 对应处理服务时,组件的实例化内容。一般是组件的小写。 - appid : 前端系统传过来的标识,未被处理,用于预留。 - system: 后端系统的标识,用于找到对应的系统配置。实例化common用的。 # 项目结构 ``` Great #父级 ├── demo ├── great-boot # spring-boot ├── great-tomcat # 整合tomcat. ├── great-context # 核心上下文 ├── great-doc # 文档 ├── great-gather-plun # 聚合所有组件 ├── great-plun-cache # 缓存组件 ├── great-plun-db # 数据库组件 ├── great-plun-http # http组件 ├── great-servlert # 整合servlert协议. ├── great-socket # 整合tcp协议. ``` # 演示环境: ## 说明 - 目前演示环境只是单机模式的组件。 - 只能查询和新增,其他操作不支持。 - 切勿添加敏感信息 - 黑客大大们,请手下留情。 ## 步骤 - 连接数据库 连接信息: jdbc:mysql://49.233.10.60:33306/great?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&nullCatalogMeansCurrent=true 账户: great_public 密码: great_public - 添加配置 > 配置表为: great_configure_data - 添加服务 > 脚本表为: great_script_init 在这里编码,直接保存就能使用了。 如: path script hello return "hello word"; ## POST 访问 orm insert http://49.233.10.60:9190/api/{{appid}}/{{system}}/ 如: http://49.233.10.60:9190/api/appid-test/system-test/orm/insert POST /orm/insert > Body 请求参数 ```json { "table" : "test", "appid" : "appid-appid", "key" : "key1" } ``` # 编写代码 ## 颠覆常规编码 如果熟悉的话直接编码.保存就能访问这个接口了。 ## 类似于 spring-boot 项目的 controller 层. ``` @Autowired HttpRequestCommon http; @Autowired JDBCSession db; // @Autowired // TxnContext context; @Autowired GreatHandler callService; public Object doService(TxnContext context){ /** * 执行的业务代码. */ // 返回也算执行的业务代码. return "hello word"; } ``` doService{ 里面的代码就是要执行的代码 } ## 需要开发idea智能提示. 见 demo 下面的 great-debug [`com.fucking.great.debug.TestDemo`点击链接](https://gitee.com/sxran/great/blob/master/demo/great-debug/src/test/java/com/fucking/great/debug/TestDemo.java) ## 直接操作表,保存. > 脚本表为: great_script_init 在这里编码,直接保存就能使用了。 如: path script hello return "hello word"; # 私有化部署. ## 导入SQL文件. 导入: great.sql `注意不要修改数据库名` ## 设置环境变量. ```bat setx /m server_ip 127.0.0.1 setx /m mysql_port 3306 setx /m mysql_username root setx /m mysql_password root pause ``` ## 启动jar - 该jar为spring-boot-2.x 项目集成。 `java -jar great-boot-2.4.1.jar` ## 正常接口为api,动态的grah为 ```java @RequestMapping("/api/{appid}/{system}/**") public void api(@PathVariable("appid") String appid, @PathVariable("system") String system, HttpServletRequest request, HttpServletResponse response) throws IOException{ } @RequestMapping("/api/{appid}/{system}/graph") public JSONObject graph(@PathVariable("appid") String appid, @PathVariable("system") String system, HttpServletRequest request, HttpServletResponse response) throws Exception{ } ``` 必须都是body传参. # 其他系统,代码集成 可以参考`great-boot`项目 ## 导入jar ### 地址 https://jitpack.io/#com.gitee.sxran.great/great-servlert/3.0.0 ### pom.xml 依赖 To get a Git project into your build: Step 1. Add the JitPack repository to your build file ```xml jitpack.io https://jitpack.io ``` Step 2. Add the dependency ```xml com.gitee.sxran.great great-servlert 3.0.0 ``` ### edit code ```java @RequestMapping("/api/{appid}/{system}/**") public void api(@PathVariable("appid") String appid, @PathVariable("system") String system, HttpServletRequest request, HttpServletResponse response) throws IOException { appid = appid.trim(); system = system.trim(); // 初始化 TxnContext txnContext = HadnlerServlet.initContextByRequest(request); // 设置appid 和 systemName 参数 txnContext.setAppid(appid); txnContext.setSystemName(system); // spring boot @PathVariable 传递带有反斜杠的参数“/” // 获得处理路径 final String path = request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).toString(); final String bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString(); // String contextPath = new AntPathMatcher().extractPathWithinPattern(bestMatchingPattern, path); //设置处理的路径 txnContext.setPath(contextPath); //调用服务处理内容 HadnlerServlet.handlerContext(response,txnContext); } ``` # 运行截图 ![db-data](https://images.gitee.com/uploads/images/2021/0630/104733_63238ea9_1842648.png "屏幕截图.png") ![hello](https://images.gitee.com/uploads/images/2021/0630/104635_c8e12489_1842648.png "屏幕截图.png") ![debug](https://images.gitee.com/uploads/images/2021/0630/104758_d36eddb2_1842648.png "屏幕截图.png") ![debug-testService](https://images.gitee.com/uploads/images/2021/0630/104658_6da8cd9d_1842648.png "屏幕截图.png") ![日志](https://images.gitee.com/uploads/images/2021/0630/104611_454eef25_1842648.png "屏幕截图.png") # 贡献代码 - 请提供丰富的代码注释. - 编写的组件尽量不要再引入第三方pom. - 调用第三API(如阿里云,和腾讯云...),请不要当成组件提交。请丰富基础服务。 - 请往 master pl,其他分支不支持pl,切都是只读的。