From 0f300f11c80ee3e81fe88e2398cfb915b97bb9ab Mon Sep 17 00:00:00 2001 From: NananY <143098798+NananY001@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=A4=9A=E7=BA=A7=E5=8C=85?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-fastapi-backend/common/router.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ruoyi-fastapi-backend/common/router.py b/ruoyi-fastapi-backend/common/router.py index 77f707897..729a0abf6 100644 --- a/ruoyi-fastapi-backend/common/router.py +++ b/ruoyi-fastapi-backend/common/router.py @@ -305,10 +305,21 @@ def _find_controller_files(self) -> list[str]: """ 查找所有controller目录下的py文件 + 支持任意层级的业务包嵌套:module_xxx/.../controller + (代码生成按点号包路径,如 module_xx.xxx、module_x.y.z, + 产出的 controller 落在任意深度均可被注册)。 + :return: py文件路径列表 """ - pattern = os.path.join(self.project_root, '*', 'controller', '[!_]*.py') - return sorted(glob.glob(pattern)) + patterns = [ + os.path.join(self.project_root, '*', 'controller', '[!_]*.py'), + os.path.join(self.project_root, 'module_*', '**', 'controller', '[!_]*.py'), + ] + files: list[str] = [] + for pattern in patterns: + files.extend(glob.glob(pattern, recursive=True)) + + return sorted(set(files)) def _import_module_and_get_routers(self, controller_files: list[str]) -> list[tuple[str, APIRouter]]: """