{"id":23269023,"url":"https://github.com/guqing/creek","last_synced_at":"2025-10-19T05:32:09.402Z","repository":{"id":53236988,"uuid":"229532885","full_name":"guqing/creek","owner":"guqing","description":"使用Spring Security + JWT Token + RBAC的方式实现认证和授权，持久层使用Mybatis plus。避免每次重复编写认证和授权功能、角色管理、异常处理、参数校验等代码，直接上手业务代码，不再烦恼于构建项目与风格统一。","archived":false,"fork":false,"pushed_at":"2022-06-04T17:12:34.000Z","size":3872,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-08T00:39:32.306Z","etag":null,"topics":["caffeine-cache","jwt-token","lombok-maven","mysql-database","spring-data-jpa","spring-security","springboot"],"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/guqing.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}},"created_at":"2019-12-22T07:23:58.000Z","updated_at":"2025-01-03T21:48:30.000Z","dependencies_parsed_at":"2022-08-19T19:30:26.221Z","dependency_job_id":null,"html_url":"https://github.com/guqing/creek","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/guqing/creek","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guqing%2Fcreek","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guqing%2Fcreek/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guqing%2Fcreek/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guqing%2Fcreek/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guqing","download_url":"https://codeload.github.com/guqing/creek/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guqing%2Fcreek/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271414984,"owners_count":24755628,"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-08-20T02:00:09.606Z","response_time":69,"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":["caffeine-cache","jwt-token","lombok-maven","mysql-database","spring-data-jpa","spring-security","springboot"],"created_at":"2024-12-19T17:40:48.838Z","updated_at":"2025-10-19T05:32:09.283Z","avatar_url":"https://github.com/guqing.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Creek\n⚠️注意：本项目代码正在进行重构，目前无法运行 \n## 简介\n这是一个基于`SpringBoot 3.0.0.M1`，用于搭建`RESTful API`快速开发脚手架, 使用`Spring Security` + `JWT Token` + `RBAC`\n的方式实现认证和授权，持久层使用`Mybatis plus`。避免每次重复编写认证和授权功能、角色管理、异常处理、参数校验等代码，直接上手业务代码，不再烦恼于构建项目与风格统一。\n\n## 所需环境\n\n- IDE：IntelliJ IDEA 或者 STS（Spring Tools Suite）\n- 工具：Maven，Lombok 插件\n- JDK：17+\n\n### 安装Lombok插件\n\n1. 本项目使用了 Lombok，运行 `Creek` 之前请检查 IDE 是否已经安装好了 Lombok 插件。\n2. 对于IntelliJ IDEA，请在设置中启用 `Build -\u003e Execution -\u003e Deployment/Annotation Processors` 的 `Enable annotation processing`。\n\n### 可选设置\n\n本项目因为适用 springboot3.0.0 因此只能适用`jdk17`以上\n\n然后点击如下图所示位置的项目结构设置\n![项目结构设置](./docs/images/2020-10-22_10-19.png)\n\n如下修改jdk版本为`1.8`\n![修改jdk](./docs/images/2020-10-22_10-20.png)\n\n点击`File-\u003eSettings`设置`Java complier`如下图所示\n![修改java complier](./docs/images/2020-10-22_10-29.png)\n\n## 运行项目\n\n1.本项目默认使用`H2`数据库，首次启动修改如下配置会自动创建数据库文件并初始化\n\n```properties\nspring:\ndatasource:\ninitialization-mode:always\n```\n\n启动后在将改配置值改为`never`，防止每次都初始化\n\n2.运行`AppApplication`\n\n## 特性\n\n- 认证和授权\n- security权限管理\n- 全局异常处理\n- 全局参数校验\n- 统一项目风格\n- 支持第三方社交登录\n- 基于角色的权限控制\n- 动态路由\n- 基于自定义指令细划到按钮级别权限控制\n- aop+自定义注解处理日志\n\n[前端使用示例项目](https://github.com/guqing/creek-ui)\n\n## 项目预览\n\n![workplace](./docs/preview/workplace.png)\n![login_log](./docs/preview/login_log.png)\n![menu_list.png](./docs/preview/menu_list.png)\n![role_list.png](./docs/preview/role_list.png)\n![profile](./docs/preview/profile.png)\n\n## 项目结构\n\n```\nsrc\n|─main\n|  |─java\n|  |  |─xyz.guqing.creek                  ------ 根包名\n|  |  |  |─aspect                          ------ aop切面\n|  |  |  |─config                         ------ springboot自动配置\n|  |  |  |─controller                     ------ controller接口\n|  |  |  |─mapper                      \t  ------ mybatis mapper接口\n|  |  |  |─exception                      ------ 自定义异常\n|  |  |  |─service                        ------ service层\n|  |  |  |─model                          ------ 模型类\n|  |  |  |  |─entity                      ------ 数据库对应的实体\n|  |  |  |  |─enums                       ------ 枚举\n|  |  |  |  |─params                      ------ controller中入参数修改类型的入参数命名为xxxParam查询的为xxxQuery\n|  |  |  |  |─dto                         ------ controller出参实体\n|  |  |  |  |─annotation                  ------ 自定义注解\n|  |  |  |  |─dos                         ------ 数据库组合实体例如关联查询需要多表字段组合\n|  |  |  |  |─bo                          ------ 业务逻辑实体，例如支付service方法调用支付方法传递组合参数\n|  |  |  |  |─properties                  ------ 自动配置properties实体\n|  |  |  |─factory                        ------ 自定义工厂类\n|  |  |  |─event                          ------ 自定义事件\n|  |  |  |─listener                       ------ 事件监听器\n|  |  |  |─convert                        ------ 自定义类型转换器\n|  |  |  |─handler                        ------ 处理器类\n|  |  |  |─security                       ------ spring security安全控制\n|  |  |  |─utils                          ------ 自定义工具类\n|  |─resources\n|  |  |─db                                ------ 数据库sql\n|  |  |─mapper                            ------ mybatis自定义mapper xml\n|  |  |─templates                         ------ 模板文件例如邮件模板\n|─test\n|  |─java\n|  |  |─com.happyland.ums\n|  |  |  |─service                        ------ service层单元测试类\n|  |  |  |─utils                          ------ 自定义工具单元测试类\n```\n\n## 编码风格\n\n### controller风格\n\n#### controller入参示例\n\n```java\n@PostMapping(\"/save\")\npublic ResultEntity\u003cString\u003e createOrUpdate(@RequestBody @Valid MenuParam menuParam){\n    Menu menu=menuParam.convertTo();\n    menuService.saveOrUpdate(menu);\n    return ResultEntity.ok();\n    }\n```\n\n因为是创建方法属于修改数据因此参数为xxxParam，这样的好处还便于使用注解做参数校验\n\n```java\n\n@Data\n@JsonIgnoreProperties(ignoreUnknown = true)\npublic class MenuParam implements InputConverter\u003cMenu\u003e {\n    private Long id;\n\n    private Long parentId;\n\n    @NotBlank(message = \"菜单标题不能为空\")\n    @Size(max = 150, message = \"菜单标题不能字符长度不能大于 {max}\")\n    private String title;\n\n    private String type;\n\n    private String path;\n\n    // ...\n\n    @Override\n    public Menu convertTo() {\n        if (parentId == null) {\n            parentId = 0L;\n        }\n        if (sortIndex == null) {\n            sortIndex = 0L;\n        }\n\n        if (keepAlive == null) {\n            keepAlive = false;\n        }\n\n        type = MenuType.valueFrom(type);\n\n        return InputConverter.super.convertTo();\n    }\n}\n```\n\n所有Param方法需要实现InputConverter接口泛型对应数据库实体，所有Param的参数转换都再controller中做，xxxQuery可以除外，如果需要赋默认值或者类型或者名称转换等则覆盖convertTo方法，该方法灵活运用,例如赋值默认值后使用父类转换逻辑则返回InputConverter.super.convertTo()\n即可,也可以如下\n\n```java\n@Override\npublic Menu convertTo(){\n    Menu menu=new Menu();\n    BeanUtils.copyProperties(this,menu);\n    menu.setTitle(this.name);\n    menu.setPath(this.name+\"/\"+this.title);\n    return menu;\n    }\n```\n\n可以满足绝大部分的类型转换问题，从而减少对业务逻辑的干扰,提高可读性和代码简洁度，Param转数据库实体时使用如下方式\n\n```java\nMenu menu=menuParam.convertTo();\n```\n\n#### controller出参示例\n\n```java\n@GetMapping(\"/options\")\npublic ResultEntity\u003cList\u003cRoleDTO\u003e\u003elistAll(){\n    List\u003cRole\u003e list=roleService.list();\n    return ResultEntity.ok(convertTo(list));\n    }\nprivate List\u003cRoleDTO\u003e convertTo(List\u003cRole\u003e list){\n    if(CollectionUtils.isEmpty(list)){\n    return Collections.emptyList();\n    }\n    return list.stream()\n    .map(role-\u003e(RoleDTO)new RoleDTO().convertFrom(role))\n    .collect(Collectors.toList());\n    }\n```\n\n对于分页,可以使用如下方式\n\n```java\n@GetMapping(\"list\")\npublic ResultEntity\u003cPageInfo\u003cRoleDTO\u003e\u003elistBy(RoleQuery roleQuery,PageQuery pageQuery){\n    roleQuery.setPageQuery(pageQuery);\n    Page\u003cRole\u003e pageInfo=roleService.listBy(roleQuery);\n    return ResultEntity.okList(pageInfo,role-\u003enew RoleDTO().convertFrom(role));\n    }\n```\n\ncontroller出参一律返回DTO对于模板引擎需要的参数返回xxxVO,不得直接返回数据库实体,参数转换同样再controller中做，除非是需要特殊数据controller无法转换则再service中返回DTO\n\n```java\n\n@Data\npublic class RoleDTO implements OutputConverter\u003cRoleDTO, Role\u003e {\n    private Long id;\n    private String roleName;\n    private String remark;\n    private LocalDateTime createTime;\n    private Set\u003cLong\u003e menuIds;\n}\n```\n\n如上DTO实现OutputConverter便于出参类型转换，实现该接口以后数据库实体转DTO则如下操作即可\n\n```java\nRoleDTO roleDto=new RoleDTO().convertFrom(role)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguqing%2Fcreek","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguqing%2Fcreek","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguqing%2Fcreek/lists"}