Kungfu Framework

website·Indexed 32 days ago

https://kungfu.wang/

An enhancement framework for JFinal designed to build RESTful APIs. It features a code generator for automating Java Web application development, support for dynamic parameter parsing, tree-structured queries, and a JWT-based authentication interceptor. The ecosystem includes Kungfu-Admin, a backend management system, and Kungfu-Admin-UI, a frontend based on Vue 3.2, TypeScript, Vite 4, and Pinia.

Tokens
14.8K
Snippets
57
Records
68
Agent score
60%

What's inside Kungfu

  1. Overview of KungFuPanda Code Templates

    The KungFuPanda code generator uses pre-defined code templates with placeholders and variables to automate the creation of Java source code. This ensures consistent code style, increases development efficiency, and allows for custom configurations. The generator utilizes the JFinal Enjoy template engine, which is characterized by high performance, lightweight execution (no requirement for a Web container like Tomcat), and high customizability.
  2. Overview of the Kungfu JFinal Enhancement Framework

    Kungfu is an elegant enhancement framework based on JFinal for building standard MVC Java Web projects. It aims to accelerate development through several key capabilities:

    • Simplified CRUD: Supports automatic construction of SQL query statements from dynamic parameters.
    • Code Scaffolding: Provides a one-click layered code generation tool.
    • Controller Layer Acceleration: Offers standardized exception handling, result formatting, and flexible parameter acquisition, validation, and conversion.
    • Service Layer Acceleration: Supports dynamic parameter parsing for dynamic queries, tree-structure queries, and existence queries.
    • Core Utilities: Handles permissions, stateless services, and type conversion with options for high customization (DIY).
  3. Overview of Kungfu for JFinal

    Kungfu is a rapid development library specifically designed for JFinal to build RESTful API services. It provides a flexible scaffolding to simplify CRUD operations and accelerate the development of the Controller and Service layers. Key features include:

    • Rapid construction of JFinal RESTful API projects.
    • Simple and flexible code generation capabilities.
    • Support for dynamic construction of query SQL statements.
    • Automated input parameter acquisition and conversion.
    • Integrated parameter validation with friendly error messaging for front-end clients.
    • Standardized API documentation for efficient front-end/back-end integration.
  4. Overview of RESTful API parameter types

    RESTful APIs typically use four types of input parameters:

    1. Path Parameters: Extracted from the URL path (e.g., /users/:id).
    2. Query Parameters: Appended to the URL after a ? (e.g., /users?id=123&name=John).
    3. Request Body: The main body of the request, usually JSON or XML, sent via POST, PUT, or PATCH.
    4. Request Headers: Key-value pairs providing metadata (e.g., Content-Type: application/json).
  5. Overview of Kungfu-Admin-UI features

    Kungfu-Admin-UI is a backend management framework built on the Geeker-Admin framework. It utilizes a modern tech stack including Vue 3.2, TypeScript, Vite 4, Pinia, and Element-Plus. Key features include:

    • ProTable Component: A configuration-based table component using columns to increase development efficiency.
    • State Management: Uses Pinia with a persistence plugin.
    • Network Layer: TypeScript-based Axios wrapper with request interception and cancellation.
    • UI/UX: Support for dark mode, i18n internationalization, and Element component size switching.
    • Routing & Security: VueRouter for permission interception, button-level access control, and lazy loading.
    • Performance: Multi-level nested page caching via KeepAlive.
    • Developer Tooling: Integrated ESLint, Stylelint, Prettier, and a standardized commit workflow using husky, lint-staged, and commitlint.
  6. Overview of Kungfu-Admin Backend Management System

    Kungfu-Admin is an open-source, reusable backend management system designed for rapid development. It is built using the Kungfu backend framework (an enhancement of JFinal) and the Geeker-Admin frontend framework. It is suitable for various Web applications, including website administration backends, member centers, CMS, CRM, and OA systems.
  7. Overview of the Kungfu Code Generator

    The Kungfu Code Generator is a tool designed to automatically generate Java Web application code based on user-defined data models, database table structures, and configuration files. It aims to accelerate project development, reduce coding errors by adhering to best practices, improve maintainability through consistent structure, and facilitate team collaboration by enforcing a unified coding style.
  8. Understand the relationship between Kungfu and JFinal

    Kungfu is an enhancement framework for JFinal. It is designed to be easy to learn and use, providing a powerful and flexible scaffold that significantly simplifies CRUD operations and accelerates the development of the controller and service layers.
  9. Perform tree-table paginated queries

    For tree-table structures, passing a code (e.g., menuCode) in the modelMap is automatically interpreted by the server as a parentCode filter to retrieve the child records of that specific node.
    // Request
    {
      "pageNumber": 1,
      "pageSize": 20,
      "orderColumnName": "updateTime",
      "orderBy": "desc",
      "modelMap": {
        "menuCode": "sys"
      }
    }
    
    // Resulting SQL
    select * 
      from sys_menu 
     where 1=1 
       and parent_code = 'sys'
     order by update_time desc
     limit 0,20;
  10. Implement user authentication using JWT

    The system uses JSON Web Tokens (JWT) for interface access authentication. The process involves the server issuing a token upon successful login, which the client stores (e.g., in cookies or localStorage) and sends in the Authorization header for subsequent requests. The server validates the token by checking expiration, signature correctness, and user information before granting access to the resource. If validation fails, a 401 (Unauthorized) status code is returned.
    Authorization: Bearer <your_jwt_token>
  11. Implement a Kungfu Panda Service for CRUD operations

    The SysApiService demonstrates how to implement a service layer extending KungfuService. It handles the business logic for saving or updating a model, including setting audit fields like createUser, createTime, updateUser, and updateTime based on the current UserInfo and system date.
    package io.kungfu.panda.modules.sys.service;
    
    import io.kungfu.panda.modules.sys.model.SysApi;
    import org.kungfu.core.KungfuService;
    import org.kungfu.core.R;
    import org.kungfu.core.UserInfo;
    
    import java.util.Date;
    
    public class SysApiService extends KungfuService<SysApi> {
        private final SysApi dao = SysApi.dao;
    
        public R saveOrUpdate(SysApi sysApi, UserInfo userInfo) {
            if (sysApi == null) {
                return R.fail(630, "信息不能为空");
            }
    
            Date date = new Date();
            if (sysApi.getId() != null) {
                sysApi.setUpdateUser(userInfo.getUserName());
                sysApi.setUpdateUserId(userInfo.getUserId());
                sysApi.setUpdateTime(date);
                if (sysApi.update()) {
                    return R.ok("更新成功");
                }
                return R.fail(641, "更新失败");
            } else {
                sysApi.setCreateUser(userInfo.getUserName());
                sysApi.setCreateUserId(userInfo.getUserId());
                sysApi.setCreateTime(date);
                if (sysApi.save()) {
                    return R.ok("保存成功");
                }
                return R.fail(640, "保存失败");
            }
        }
    }
  12. Integrate Swagger API documentation using jfinal-swagger-knife4j

    To provide online API documentation, configure the Swagger routes, plugins, and handlers within your JFinal configuration methods.
    @Override
    public void configRoute(Routes me) {
        // swagger route
        me.add(new SwaggerRoutes());
    }
    
    @Override
    public void configPlugin(Plugins me) {
        // swagger plugin
        me.add(new SwaggerPlugin());
    }
    
    @Override
    public void configHandler(Handlers me) {
        // swagger handler
        me.add(new SwaggerHandler());
    }