{"id":23529534,"url":"https://github.com/cctyl/jdbctemplateplus","last_synced_at":"2025-10-14T15:33:39.305Z","repository":{"id":105194710,"uuid":"543485582","full_name":"cctyl/jdbcTemplatePlus","owner":"cctyl","description":"对jdbcTemplate 进行增强，保留灵活性的同时，对嵌套的子对象也进行封装。","archived":false,"fork":false,"pushed_at":"2022-11-10T03:01:26.000Z","size":94,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-10T15:45:11.818Z","etag":null,"topics":["java","jdbc","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cctyl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-30T07:43:07.000Z","updated_at":"2025-03-09T02:01:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"632f6254-0fa5-4640-87bc-1871b684319a","html_url":"https://github.com/cctyl/jdbcTemplatePlus","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cctyl/jdbcTemplatePlus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cctyl%2FjdbcTemplatePlus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cctyl%2FjdbcTemplatePlus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cctyl%2FjdbcTemplatePlus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cctyl%2FjdbcTemplatePlus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cctyl","download_url":"https://codeload.github.com/cctyl/jdbcTemplatePlus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cctyl%2FjdbcTemplatePlus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019320,"owners_count":26086711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jdbc","sql"],"created_at":"2024-12-25T21:12:21.164Z","updated_at":"2025-10-14T15:33:39.290Z","avatar_url":"https://github.com/cctyl.png","language":"Java","readme":"### 简介\n\njdbcTemplatePlus，针对jdbcTemplate 进行了封装，用于弥补JPA 等全自动框架灵活性不足的问题。\ntodo: 本质只使用了jpa的Id 注解和 @Column注解，后续会逐步创建独立注解，并且支持灵活切换\n### 特点\n\n- 针对多表查询嵌套对象的封装，达到类似JPA 的oneToMany、ManyToMany 等注解的作用。\n- 相较于JPA，自定义程度高，灵活性强\n- 无侵入，耦合低，仅为了兼容以往jpa项目，使用jpaTable\\Id\\Column 注解。jdbcTemplate为外部传入\n- 支持注解：@MappedSuperclass、@Transient\n\n\n### 涉及到一些问题\n\n- 获得的结果是Integer类型，而实体类的类型是Long。涉及到的类型转换器\n\n- 枚举值转换枚举对象\n\n- 成员对象是集合接口类型，但是接口类型不确定的情况下（List，Set，Collection），如何生成对应的实现类？如果是Set接口，应该生成什么实现类？如果是具体的实现类例如HashSet，怎么进行处理？\n\n- 实体类属性与表中字段的映射，通过注解以及反射的方式\n\n- 在简化重复步骤的同时，又需要插入定制化的代码，怎么实现？依靠类似函数式接口，抽象方法、回调方法等来实现\n\n- lambda 表达式来传递需要封装的子对象\n\n  此处涉及到的是 lambda表达式中的writeReplace方法\n\n- 通过反射获取集合的泛型\n\n\n\n### 引入方式\n\n\n- maven依赖\n\n  ```xml\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.github.cctyl\u003c/groupId\u003e\n            \u003cartifactId\u003ejdbcTemplatePlus\u003c/artifactId\u003e\n            \u003cversion\u003e1.0.3\u003c/version\u003e\n        \u003c/dependency\u003e\n  ```\n\n### 使用方法\n\n设有 User、Role、UserRole 三张表。其中User表中含有一个成员`List\u003cRole\u003e roleList`，并且还有一个Role role（无实际意义，仅做演示）。\n\n此时希望查询User时，直接将roleList 封装好，以及Role封装好。并且不需要过多的代码。\n\n那么示例如下：\n\n```java\n/*\n            目标sql为\n                SELECT\n                  r.*\n                FROM\n                  acl_user u\n                  LEFT JOIN acl_user_role ur\n                    ON u.`id` = ur.`user_id`\n                  LEFT JOIN acl_role roleList\n                    ON ur.`role_id` = roleList.id\n                  Left join acl_role r\n                  \tON ur.`role_id` = r.id\n                WHERE u.id = 1 ;\n\n*/   \n\n        @Test\n        public void test01LambdaPlus() {\n    \n            // =========================参数准备========================\n            SqlGenrator sqlGen = new SqlGenrator();\n            TargetTable\u003cString, AclUser\u003e tUser = sqlGen.targetTable(AclUser.class);\n            TargetTable\u003cString, AclRole\u003e tRoleList = sqlGen.targetTable(AclUser::getRoleList);\n            TargetTable\u003cString, AclRole\u003e tRole = sqlGen.targetTable(AclUser::getRole);\n            TargetTable\u003cString, AclUserRole\u003e tUserRole = sqlGen.targetTable(AclUserRole.class);\n    \n            // ======================查询部分===========================\n            //如果你只需要一部分字段，则显式的声明这部分字段\n            String column = sqlGen.genColumn(tUser.columns(AclUser::getId,AclUser::getUsername),\n                    tRoleList.columns(AclRole::getRoleName,AclRole::getId),\n                    tRole.columns(AclRole::getRoleName));\n    \n            //如果你需要全部字段\n    //        String column = sqlGen.genColumn(tUser, tRoleList, tRole);\n    \n    \n            sqlGen.select(column)\n                            .from(tUser)\n                            .lJoin(tUserRole)\n                            .on(tUser.id() + \"=\" + tUserRole.col(\"user_id\"))\n            \n                            .lJoin(tRoleList)\n                            .on(tUserRole.col(AclUserRole::getRoleId) + \"=\" + tRoleList.id())\n            \n                            .lJoin(tRole)\n                            .on(tUserRole.col(AclUserRole::getRoleId) + \"=\" + tRole.id())\n            \n                            .where(tUser.id() + \"=:userId\")\n                            .and(tUser.col(AclUser::getToken) + \"=:token\")\n                            .and(tUser.col(AclUser::getPassword) + \"=:password\")\n                            .or(tUser.col(AclUser::getPassword) + \"=:password\")\n                            .addParam(\"userId\", 1)\n                            .addParam(\"token\", \"sss\")\n                            .addParam(\"password\", \"e10adc3949ba59abbe56e057f20f883e\");\n    \n            // ===================封装部分==============================\n            List\u003cAclUser\u003e genrator = new MapToTable\u003cAclUser, String\u003e() {\n                @Override\n                public void mapToChildObj(List\u003cMap\u003cString, Object\u003e\u003e tempList, AclUser mainObj) {\n                    //在这里进行子对象封装\n                    //roleList\n                    mapMany(mainObj, tRoleList, AclUser::getRoleList);\n    \n                    //role\n                    mapOne(mainObj, tRole, AclUser::getRole);\n    \n                }\n            }.genrator(sqlGen.queryForList(namedParameterJdbcTemplate), tUser);\n    \n            System.out.println(\"end\");\n        }\n\n\n\n\n\n```\n\nsqlGen 直接直接传入String sql（但是要求表名从targetTable 中取出），也可以通过调用方法拼接的方式。\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcctyl%2Fjdbctemplateplus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcctyl%2Fjdbctemplateplus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcctyl%2Fjdbctemplateplus/lists"}