FastChar MVC Framework
website·Indexed 31 days ago
https://www.fastchar.com/An open-source, Java-based WEB+ORM MVC framework designed for high development efficiency with low learning costs and zero configuration. FastChar provides a suite of core components including FastAction controllers, FastEntity ORM, and FastScanner, along with integrated support for Caffeine, Redis, EhCache, Freemarker, Thymeleaf, and various message queues like RabbitMQ and RocketMQ.
What's inside FastChar
- FastChar is a framework designed to allow developers to easily and quickly utilize high-quality third-party tool libraries. It comes pre-integrated with numerous functional components, enabling rapid connection to third-party tools with minimal configuration. FastChar maintains the original behavior of these tools by interfacing via native APIs.
Overview of the FastChar MVC Framework
FastChar is an open-source, free Java-based MVC framework that integrates Web and ORM capabilities. It is designed to follow general Web framework rules while prioritizing low learning costs, minimal code, and zero configuration to increase development efficiency. Unlike frameworks that rely heavily on annotations (such as Spring), FastChar advocates for development using native APIs and highly readable programming patterns, making it suitable for teams needing rapid Web application development.Overview of FastChar Database Automation
FastChar provides a database automation feature that synchronizes XML configurations with the actual database. It automatically performs the following operations: creating the database if it doesn't exist, creating tables if they don't exist, adding missing columns, and modifying column attributes if they differ from the XML definition.
Critical Principle: FastChar follows an 'Add-Only' (只增不删) policy. It will never delete databases, tables, columns, configurations, or data.
Supported databases include: MySQL, SQL Server, and Oracle. This feature is optional; if no
fastchar-database-*.xmlfiles are created, automation is not used.Overview of FastScanner in FastChar
FastScanner is the core component of FastChar. It automatically starts during project initialization to perform a global scan of project files, including local files and referenced JAR packages (provided the JARs allow scanning). This mechanism enables the automated registration and loading of relevant classes and files.Overview of FastChar Template Engine support
FastChar integrates three popular template engines: Freemarker, Thymeleaf, and Velocity. Developers can access these engines and perform rendering operations using theFastChar.getTemplates()method.Get the FastDB utility instance
FastChar provides a built-in database read/write tool calledFastDB. Developers can obtain the utility object using theFastChar.getDB()method.FastDB db = FastChar.getDB();FastChar Framework Design and Performance Overview
FastChar is designed for simplicity and high performance. It features a 'near-zero configuration' setup and utilizes the Builder design pattern to improve code flexibility and readability. To ensure high concurrency and low memory footprint, the framework employs class pre-loading and parsing.Implement modularity using FastChar plugins
FastChar supports the dynamic loading, updating, and unloading of plugin module JAR packages. This architecture ensures absolute isolation between modules and reduces coupling.Configure a Linux server stack for project deployment
For general server configurations, it is recommended to use a stack consisting of Nginx, Tomcat (version 7.0 or higher), and MySQL (version 5.7 or 8.0+). In this architecture, Nginx handles all static resources, while the Tomcat container processes Java-based requests. Nginx is utilized for its strengths as a web server, proxy server, and load balancer, providing high concurrency, stability, and health check capabilities.Nginx + Tomcat (7.0+) + MySQL (5.7 or 8.0+)Perform CRUD operations with FastEntity
FastEntity provides a flexible way to perform database operations using theset()method to define field values and specific action methods for persistence.// 1. Create/Insert FcUserEntity fcUserEntity = new FcUserEntity(); fcUserEntity.set("userNickName", "Nickname"); fcUserEntity.set("userCity", "Hefei"); fcUserEntity.save(); // 2. Query FcUserEntity queryEntity = new FcUserEntity(); List<FcUserEntity> results = queryEntity.select(); String nickName = results.get(0).getString("userNickName"); // 3. Delete (based on primary key) FcUserEntity deleteEntity = new FcUserEntity(); deleteEntity.set("userId", 1); deleteEntity.delete(); // 4. Update (based on primary key) FcUserEntity updateEntity = new FcUserEntity(); updateEntity.set("userId", 1); updateEntity.set("userNickName", "New Nickname"); updateEntity.update();Set up a FastChar project using Maven
To set up a FastChar project (version 2.0.0 or higher) using Maven, add the dependency to yourpom.xml, create an action class that extendsFastActionto define your route and logic, and deploy the project to a servlet container like Tomcat.<!-- Step 1: Add dependency to pom.xml --> <dependency> <groupId>com.fastchar</groupId> <artifactId>fastchar</artifactId> <version>2.0.2</version> </dependency>// Step 2: Create an action class extending FastAction public class TestAction extends FastAction { /** * Define the routing address */ @Override protected String getRoute() { return "/test"; } public void index() { responseText("搭建成功!"); } }// Step 3: Access via browser (Example: http://localhost:8080/FastCharTest/test/)
Implement a FastAction interceptor using IFastInterceptor
TheIFastInterceptorinterface is used to intercept requests directed to aFastAction. Within theonInterceptormethod, developers can add parameters to the template engine, add additional HTTP request parameters to theFastActionobject, and must callfastAction.invoke()to proceed to the next operation.public class WebSiteInterceptor implements IFastInterceptor { @Override public void onInterceptor(FastAction fastAction) throws Exception { // Add parameters to the template engine FastChar.getTemplates().put("http", fastAction.getProjectHost()); // Add additional HTTP request parameters fastAction.addParam("other", "Additional parameter!"); // Continue execution fastAction.invoke(); } }