CN103647828A - REST-based JAVA MVC system and data processing method thereof - Google Patents
REST-based JAVA MVC system and data processing method thereof Download PDFInfo
- Publication number
- CN103647828A CN103647828A CN201310676194.2A CN201310676194A CN103647828A CN 103647828 A CN103647828 A CN 103647828A CN 201310676194 A CN201310676194 A CN 201310676194A CN 103647828 A CN103647828 A CN 103647828A
- Authority
- CN
- China
- Prior art keywords
- data
- request
- server
- client
- filter
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Information Transfer Between Computers (AREA)
Abstract
本发明公开了一种基于REST的JAVA MVC系统及其数据处理方法,包括客户端发送符合REST规范的数据请求到服务器;服务器上的过滤器拦截数据请求,将数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则过滤器将数据请求的路径与服务器目录下的资源路径进行匹配,若匹配不成功则发送错误页面给客户端;若匹配成功则将匹配的服务器目录下的资源信息发送给客户端;若匹配成功则通过与数据请求的路径匹配的所述路由表中的资源路径,该过滤器将数据请求传送到服务器上的MVC框架中相应的控制器中;所述控制器接收数据请求并进行处理,最后服务器将处理后的结果发给客户端。因此,本发明能够实现快速开发、简单的配置。
The invention discloses a REST-based JAVA MVC system and a data processing method thereof, including sending a data request conforming to the REST specification from a client to a server; If the match is unsuccessful, the filter will match the path of the data request with the resource path in the server directory. If the match is unsuccessful, an error page will be sent to the client; if the match is successful, the filter will match the resource path in the server directory The resource information is sent to the client; if the match is successful, the filter transmits the data request to the corresponding controller in the MVC framework on the server through the resource path in the routing table matched with the path of the data request; The controller receives the data request and processes it, and finally the server sends the processed result to the client. Therefore, the present invention enables rapid development and simple configuration.
Description
技术领域 technical field
本发明涉及计算机技术领域,特别是指一种基于REST的JAVA MVC系统及其数据处理方法。 The present invention relates to the field of computer technology, in particular to a REST-based JAVA MVC system and a data processing method thereof. the
背景技术 Background technique
REST全名是REpresentational State Transfer(表述性状态转移)的缩写。REST指的是一组架构约束条件和原则,满足这些约束条件和原则的应用程序或设计就是RESTful。REST定义了一组体系架构原则,您可以根据这些原则设计以系统资源为中心的Web服务,包括使用不同语言编写的客户端如何通过HTTP处理和传输资源状态。如果考虑使用REST的Web服务数量,REST近年来已经成为最主要的Web服务设计模式。事实上,REST对Web的影响非常大,由于其使用相当方便,已经普遍地取代了基于SOAP和WSDL的接口设计。 The full name of REST is the abbreviation of REpresentational State Transfer (expressive state transfer). REST refers to a set of architectural constraints and principles, and an application or design that satisfies these constraints and principles is RESTful. REST defines a set of architectural principles by which you can design system resource-centric web services, including how resource states are processed and transmitted over HTTP by clients written in different languages. If you consider the number of web services using REST, REST has become the most dominant web service design pattern in recent years. In fact, REST has a great impact on the Web, because it is quite convenient to use, it has generally replaced the interface design based on SOAP and WSDL. the
MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据显示分离的方法,这个方法的假设前提是如果业务逻辑被聚集到一个部件里面,而且界面和用户围绕数据的交互能被改进和个性化定制而不需要重新编写业务逻辑MVC被独特的发展起来用于映射传统的输入、处理和输出功能在一个逻辑的图形化用户界面的结构中。 The full name of MVC is Model View Controller, which is the abbreviation of model (model)-view (view)-controller (controller). The premise of the method is that if the business logic is aggregated into a component, and the interface and user interaction around the data can be improved and customized without rewriting the business logic, MVC is uniquely developed to map traditional input, Processing and output functions are organized in a logical GUI. the
MVC是一个框架模式,它强制性的使应用程序的输入、处理和输出分开。使用MVC应用程序被分成三个核心部件:模型、视图、控制器,它们各自处理自己的任务。最典型的MVC就是JSP+Servlet+JavaBean的模式。常见的MVC如:Struts、SpringMVC等。但是MVC框架集成的功能越多,配置就会相对的越繁琐。如果想要快速开发一个小型的Web应用程序,采用这些框架会使项目看起来很臃肿,对框架的配置如果再不熟悉的话,那么会花大量时间在配置上面,得不偿失。 MVC is a framework pattern that enforces separation of application input, processing, and output. Using MVC applications are divided into three core components: model, view, controller, each of which handles its own tasks. The most typical MVC is the pattern of JSP+Servlet+JavaBean. Common MVC such as: Struts, SpringMVC, etc. But the more functions the MVC framework integrates, the more cumbersome the configuration will be. If you want to quickly develop a small web application, using these frameworks will make the project look bloated. If you are not familiar with the configuration of the framework, you will spend a lot of time on the configuration, which is not worth the candle. the
发明内容 Contents of the invention
有鉴于此,本发明的目的在于提出一种基于REST的JAVA MVC系统及其数据处理方法,能够实现快速开发、简单的配置。 In view of this, the object of the present invention is to propose a REST-based JAVA MVC system and a data processing method thereof, which can realize rapid development and simple configuration. the
基于上述目的本发明提供的一种基于REST的JAVA MVC数据处理方法,包括步骤: A kind of JAVA MVC data processing method based on REST that the present invention provides based on above-mentioned purpose, comprises steps:
S1:客户端发送符合REST规范的数据请求到服务器; S1: The client sends a data request conforming to the REST specification to the server;
S2:所述服务器上的过滤器拦截所述的数据请求,该过滤器将所述数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则进行步骤S3;若匹配成功则进行步骤S4; S2: The filter on the server intercepts the data request, the filter matches the path of the data request with the resource path in the routing table, if the matching is unsuccessful, proceed to step S3; if the matching is successful, proceed to Step S4;
S3:该过滤器将所述数据请求的路径与所述服务器目录下的资源路径进行匹配,若匹配不成功则所述服务器发送错误页面给所述的客户端;若匹配成功则将匹配的所述服务器目录下的资源信息发送给所述的客户端; S3: The filter matches the path of the data request with the resource paths in the server directory, if the matching is unsuccessful, the server sends an error page to the client; if the matching is successful, all the matched Send the resource information under the server directory to the client;
S4:通过与所述数据请求的路径匹配的所述路由表中的资源路径,该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中;所述控制器接收所述数据请求并进行处理,最后所述服务器将所述控制器处理后的结果发送给所述的客户端。 S4: Through the resource path in the routing table matched with the path of the data request, the filter transmits the data request to the corresponding controller in the MVC framework on the server; the controller The data request is received and processed, and finally the server sends the result processed by the controller to the client. the
可选地,在S2中所述过滤器在第一次使用前是需要进行初始化,其过程为: Optionally, the filter in S2 needs to be initialized before it is used for the first time, and the process is:
启动所述的服务器; start said server;
初始化过滤器; Initialize the filter;
根据所述服务器中的web.xml初始化过滤器的全局参数; Initialize the global parameters of the filter according to the web.xml in the server;
注册所述控制器到所述服务器的路由表的映射; registering the mapping of the controller to the routing table of the server;
注册监听器使过滤器处于监听状态。 Registering a listener keeps the filter in a listening state. the
进一步地,在S4中所述控制器处理接收的所述数据请求时,其具体的实施过程是控制器将数据请求发送给服务器上的MVC框架中的模型;该模型对数据请求进行业务逻辑判断,最后该模型将处理后的数据请求返回给所述的控制器。 Further, when the controller processes the received data request in S4, the specific implementation process is that the controller sends the data request to the model in the MVC framework on the server; the model performs business logic judgment on the data request , and finally the model returns the processed data request to said controller. the
进一步地,在S4中所述数据请求的路径与路由表中的资源路径匹配成功后,并且在该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中之前,进行该数据请求是否配置有监听器的判断;若该数据 请求配置了监听器,则先执行该监听器,然后根据该监听器的信息将所述的数据请求发送给相应的控制器;若该数据请求没有配置监听器,则直接将该数据请求传送给相应的控制器。 Further, after the path of the data request in S4 is successfully matched with the resource path in the routing table, and before the filter transmits the data request to the corresponding controller in the MVC framework on the server , to judge whether the data request is configured with a listener; if the data request is configured with a listener, execute the listener first, and then send the data request to the corresponding controller according to the information of the listener; if If no listener is configured for the data request, the data request is directly sent to the corresponding controller. the
进一步地,当所述控制器接收模型处理的数据结果之后,并且在该处理后的数据结果通过服务器返回给客户端之前,进行判断该处理后的数据结果是否配置有监听器;若配置有监听器,则先执行该监听器,然后再将处理后的数据请求返回给客户端;若没有配置监听器,则控制器接收模型处理的数据结果之后,服务器直接将处理后的数据请求返回给客户端。 Further, after the controller receives the data result processed by the model, and before the processed data result is returned to the client through the server, it judges whether the processed data result is configured with a listener; if configured with a listener If the listener is configured, the listener will be executed first, and then the processed data request will be returned to the client; if no listener is configured, the server will directly return the processed data request to the client after the controller receives the data result processed by the model end. the
进一步地,所述服务器将处理后的结果发送给所述客户端的过程中,若需要以视图的形式呈现给所述客户端的时候,则通过所述服务器上的MVC框架中的视图最后将处理后的结果发送给所述的客户端。 Further, when the server sends the processed result to the client, if it needs to be presented to the client in the form of a view, the processed result will be finally processed through the view in the MVC framework on the server. The results are sent to the client as described. the
另外,本发明还提供了一种基于REST的JAVA MVC系统,包括: In addition, the present invention also provides a JAVA MVC system based on REST, including:
数据请求发送单元,用于客户端发送符合REST规范的数据请求到服务器; The data request sending unit is used for the client to send a data request conforming to the REST specification to the server;
拦截匹配单元,用于所述服务器上的过滤器拦截所述的数据请求,该过滤器将所述数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则拦截匹配单元与资源路径匹配单元连接;若匹配成功则拦截匹配单元与数据处理单元连接; The intercepting matching unit is used for the filter on the server to intercept the data request, the filter matches the path of the data request with the resource path in the routing table, if the matching is unsuccessful, the matching unit and the resource path are intercepted The path matching unit is connected; if the matching is successful, the connection between the matching unit and the data processing unit is intercepted;
资源路径匹配单元,用于该过滤器将所述数据请求的路径与所述服务器目录下的资源路径进行匹配,若匹配不成功则所述服务器发送错误页面给所述的客户端;若匹配成功则将匹配的所述服务器目录下的资源信息发送给所述的客户端; The resource path matching unit is used for the filter to match the path of the data request with the resource path under the server directory, if the matching is unsuccessful, the server sends an error page to the client; if the matching is successful Then send the matching resource information under the server directory to the client;
数据处理单元,用于通过与所述数据请求的路径匹配的所述路由表中的资源路径,该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中;所述控制器接收所述数据请求并进行处理,最后所述服务器将所述控制器处理后的结果发送给所述的客户端。 A data processing unit, configured to pass the resource path in the routing table matched with the path of the data request, and the filter transmits the data request to the corresponding controller in the MVC framework on the server; The controller receives and processes the data request, and finally the server sends the result processed by the controller to the client. the
可选地,所述数据处理单元在所述数据请求的路径与路由表中的资源路径匹配成功后,并且在该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中之前,进行该数据请求是否配置有监听器的判断;若该数据请求配置了监听器,则先执行该监听器,然后根据该监听器的 信息将所述的数据请求发送给相应的控制器;若该数据请求没有配置监听器,则直接将该数据请求传送给相应的控制器。 Optionally, after the data processing unit successfully matches the path of the data request with the resource path in the routing table, and after the filter transmits the data request to the MVC framework on the server, the corresponding Before the controller, judge whether the data request is configured with a listener; if the data request is configured with a listener, execute the listener first, and then send the data request to the corresponding Controller; if the data request is not configured with a listener, the data request is directly sent to the corresponding controller. the
进一步地,当所述数据处理单元中的所述控制器接收模型处理的数据结果之后,并且在该处理后的数据结果通过服务器返回给客户端之前,进行判断该处理后的数据结果是否配置有监听器;若配置有监听器,则先执行该监听器,然后再将处理后的数据请求返回给客户端;若没有配置监听器,则控制器接收模型处理的数据结果之后,服务器直接将处理后的数据请求返回给客户端。 Further, after the controller in the data processing unit receives the data result processed by the model and before the processed data result is returned to the client through the server, it is judged whether the processed data result is configured with Listener; if a listener is configured, execute the listener first, and then return the processed data request to the client; if no listener is configured, after the controller receives the data result processed by the model, the server will directly process the The subsequent data request is returned to the client. the
进一步地,所述拦截匹配单元中过滤器在第一次使用前是需要进行初始化,首先启动所述的服务器,初始化过滤器,然后根据所述服务器中的web.xml初始化过滤器的全局参数;之后,注册所述控制器到所述服务器的路由表的映射;最后,注册监听器使过滤器处于监听状态。 Further, the filter in the intercepting matching unit needs to be initialized before the first use, first start the server, initialize the filter, and then initialize the global parameters of the filter according to the web.xml in the server; After that, register the mapping from the controller to the routing table of the server; finally, register the listener so that the filter is in a listening state. the
从上面所述可以看出,本发明提供的基于REST的JAVA MVC系统及其数据处理方法,通过服务器上的过滤器拦截符合REST规范的数据请求,将数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则过滤器将数据请求的路径与服务器目录下的资源路径进行匹配,若匹配成功则对数据进行处理。因此,本发明所述的基于REST的JAVA MVC系统及其数据处理方法将REST规范与MVC框架系统相结合,形成一种轻量级的系统及数据处理的方法。 As can be seen from the above, the REST-based JAVA MVC system and data processing method thereof provided by the present invention intercept the data request conforming to the REST specification through the filter on the server, and compare the path of the data request with the resource path in the routing table. Matching is performed. If the matching is unsuccessful, the filter will match the path of the data request with the resource path in the server directory. If the matching is successful, the data will be processed. Therefore, the REST-based JAVA MVC system and data processing method thereof of the present invention combine the REST specification with the MVC frame system to form a light-weight system and data processing method. the
附图说明 Description of drawings
图1为本发明实施例基于REST的JAVA MVC数据处理方法的流程示意图; Fig. 1 is the schematic flow sheet of the JAVA MVC data processing method based on REST in the embodiment of the present invention;
图2为本发明实施例过滤器初始化的流程示意图; Fig. 2 is the schematic flow chart of filter initialization of the embodiment of the present invention;
图3为本发明实施例基于REST的JAVA MVC系统的结构示意图。 Fig. 3 is the structural representation of the JAVA MVC system based on REST of the embodiment of the present invention. the
具体实施方式 Detailed ways
为使本发明的目的、技术方案和优点更加清楚明白,以下结合具体实施例,并参照附图,对本发明进一步详细说明。 In order to make the object, technical solution and advantages of the present invention clearer, the present invention will be described in further detail below in conjunction with specific embodiments and with reference to the accompanying drawings. the
参阅图1所示,为本发明实施例基于REST的JAVA MVC数据处理方法的流程示意图,所述基于REST的JAVA MVC数据处理方法包括以下步骤: Referring to shown in Fig. 1, be the schematic flow sheet of the JAVA MVC data processing method based on REST in the embodiment of the present invention, described JAVA MVC data processing method based on REST comprises the following steps:
步骤101,客户端发送符合REST规范的数据请求到服务器。
In
其中,所述客户端请求的方式可以为GET,POST,PUT,DELETE,HEAD等等。 Wherein, the method of the client request may be GET, POST, PUT, DELETE, HEAD and so on. the
步骤102,所述服务器上的过滤器Filer拦截所述的数据请求,该过滤器将所述数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则进行步骤103;若匹配成功则进行步骤104。
在本发明的一个实施例中,过滤器Filer在第一次使用前是需要进行初始化的,其过程为: In one embodiment of the present invention, filter Filer needs to be initialized before first use, and its process is:
步骤201:启动所述的服务器。 Step 201: Start the server. the
步骤202:初始化过滤器Filer。 Step 202: Initialize the filter Filer. the
步骤203:根据所述服务器中的web.xml初始化过滤器Filer的全局参数。 Step 203: Initialize the global parameters of the filter Filer according to the web.xml in the server. the
在本发明的实施例中,在web.xml中配置过滤器Filter,设置最基本的参数,如:项目注解类型扫描路径、控制层类文件过滤、项目文件编码、页面内容目录等。初始化过滤器Filer的全局参数后,再根据该参数全自动扫描类文件。 In the embodiment of the present invention, filter is configured in web.xml, and the most basic parameters are set, such as: project annotation type scanning path, control layer class file filtering, project file encoding, page content directory, etc. After the global parameters of the filter Filer are initialized, the class files are automatically scanned according to the parameters. the
步骤204:注册所述控制器到所述服务器的路由表的映射。 Step 204: Register the mapping from the controller to the routing table of the server. the
其中,控制器Controller通过注解编程的方式实现在路由表的映射,并通过注解的方式标识参数。 Among them, the controller implements the mapping in the routing table through annotation programming, and identifies parameters through annotation. the
步骤205:注册监听器使过滤器Filer处于监听状态。 Step 205: registering a listener so that the filter Filer is in a listening state. the
步骤103,该过滤器将所述数据请求的路径与所述服务器目录下的资源路径进行匹配,若匹配不成功则所述服务器发送404错误页面给所述的客户端;若匹配成功则将与所述服务器将所述数据请求的路径匹配的所述服务器目录下的资源路径下的资源信息发送给所述的客户端。
在实施例中,数据请求的路径与服务器目录下的资源路径匹配后,找到的资源信息可以为html、jsp、word以及图片等等形式的信息。 In an embodiment, after the path of the data request is matched with the resource path in the server directory, the resource information found may be information in the form of html, jsp, word, pictures, and the like. the
步骤104,通过与所述数据请求的路径匹配的所述路由表中的资源路径,该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中;所述控制器接收所述数据请求并进行处理,最后所述服务器将所 述控制器处理后的结果发送给所述的客户端。
在本发明的实施例中,控制器Controller处理接收的所述数据请求时,其具体的实施过程是控制器Controller将数据请求发送给服务器上的MVC框架中的模型Model。该模型Model对数据请求进行业务逻辑判断,在进行处理的过程中可能需要提取所述服务器上的数据库,最后该模型Model将处理后的数据请求返回给所述的控制器Controller。还有,该模型Model还可以将处理后的数据请求存入到所述服务器上的数据库中。 In the embodiment of the present invention, when the controller processes the received data request, the specific implementation process is that the controller sends the data request to the model Model in the MVC framework on the server. The Model performs business logic judgment on the data request, and may need to extract the database on the server during processing, and finally the Model returns the processed data request to the Controller. Also, the model Model can also store the processed data request into the database on the server. the
作为本发明的一个实施例,在所述数据请求的路径与路由表中的资源路径匹配成功后,并且在该过滤器Filer将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器controller中之前,可以进行该数据请求是否配置有监听器的判断。若该数据请求配置了监听器,则先执行该监听器,然后根据该监听器的信息将所述的数据请求发送给相应的控制器controller。若该数据请求没有配置监听器,则直接将该数据请求传送给相应的控制器controller。其中,该监听器可以设置有认证、日志、数据压缩、图片转换以及令牌等等应用。 As an embodiment of the present invention, after the path of the data request is successfully matched with the resource path in the routing table, and the filter Filer transmits the data request to the corresponding Before the controller is in the controller, it can be judged whether the data request is configured with a listener. If the data request is configured with a listener, the listener is executed first, and then the data request is sent to a corresponding controller according to the information of the listener. If the data request is not configured with a listener, the data request is directly sent to the corresponding controller controller. Wherein, the listener may be provided with applications such as authentication, log, data compression, image conversion, and token. the
作为本发明的另一个实施例中,当所述控制器controller接收模型Model处理后的结果之后,并且在该处理后的数据结果通过服务器返回给客户端之前,进行判断该处理后的数据结果是否配置有监听器。若配置有监听器,则先执行该监听器,然后再将处理后的数据请求返回给客户端。若没有配置监听器,则控制器controller接收模型Model处理后的结果之后,服务器直接将处理后的数据请求返回给客户端。 As another embodiment of the present invention, after the controller receives the processed result of the model Model, and before the processed data result is returned to the client through the server, it is judged whether the processed data result Configured with listeners. If a listener is configured, execute the listener first, and then return the processed data request to the client. If no listener is configured, the server will directly return the processed data request to the client after the controller receives the processed result of the Model. the
另外,值得说明的是所述服务器返回的处理后的数据请求可以是Json、XML、JSP、Free Mark以及Velocity等等形式的数据。在本发明的另一个实施例中所述服务器将处理后的结果发送给所述客户端的过程中,若需要以视图view的形式呈现给所述客户端的时候,例如JSP、Velocity和Free Mark等形式的数据,则通过所述服务器上的MVC框架中的视图view最后将处理后的结果发送给所述的客户端。其中,视图view接收控制器controller传送的处理后的数据请求,然后视图view将处理后的数据请求返回给所述的客户端。当然,若不需要以视图view的形式呈现给所述客户端的时候,则所述服务器直接将处理后的数据请求返回客户端。 In addition, it is worth noting that the processed data request returned by the server may be data in the form of Json, XML, JSP, Free Mark, and Velocity. In another embodiment of the present invention, when the server sends the processed result to the client, if it needs to be presented to the client in the form of a view, such as JSP, Velocity and Free Mark, etc. data, the processed result is finally sent to the client through the view view in the MVC framework on the server. Wherein, the view view receives the processed data request transmitted by the controller, and then the view view returns the processed data request to the client. Certainly, if it is not necessary to present to the client in the form of a view, the server directly returns the processed data request to the client. the
参阅图3所示,为本发明实施例基于REST的JAVA MVC系统的结构示意图,所述基于REST的JAVA MVC系统包括: Referring to shown in Fig. 3, be the structural representation of the JAVA MVC system based on REST of the embodiment of the present invention, described JAVA MVC system based on REST comprises:
数据请求发送单元301,用于客户端发送符合REST规范的数据请求到服务器。其中,所述客户端请求的方式可以为GET,POST,PUT,DELETE,HEAD等等。
The data
拦截匹配单元302,用于所述服务器上的过滤器Filer拦截所述的数据请求,该过滤器将所述数据请求的路径与路由表中的资源路径进行匹配,若匹配不成功则拦截匹配单元302与资源路径匹配单元303连接;若匹配成功则拦截匹配单元302与数据处理单元304连接。
The intercepting
在本发明的一个实施例中,过滤器Filer在第一次使用前是需要进行初始化的,拦截匹配单元302首先启动所述的服务器,初始化过滤器Filer,然后根据所述服务器中的web.xml初始化过滤器Filer的全局参数。其中,在web.xml中配置过滤器Filter,设置最基本的参数,如:项目注解类型扫描路径、控制层类文件过滤、项目文件编码、页面内容目录等。初始化过滤器Filer的全局参数后,再根据该参数全自动扫描类文件。之后,注册所述控制器到所述服务器的路由表的映射。其中,控制器Controller通过注解编程的方式实现在路由表的映射,并通过注解的方式标识参数。最后,注册监听器使过滤器Filer处于监听状态。
In one embodiment of the present invention, the filter Filer needs to be initialized before it is used for the first time, and the intercepting
资源路径匹配单元303,用于该过滤器将所述数据请求的路径与所述服务器目录下的资源路径进行匹配,若匹配不成功则所述服务器发送404错误页面给所述的客户端;若匹配成功则将与所述服务器将所述数据请求的路径匹配的所述服务器目录下的资源路径下的资源信息发送给所述的客户端。
The resource
在实施例中,数据请求的路径与服务器目录下的资源路径匹配后,找到的资源信息可以为html、jsp、word以及图片等等形式的信息。 In an embodiment, after the path of the data request is matched with the resource path in the server directory, the resource information found may be information in the form of html, jsp, word, pictures, and the like. the
数据处理单元304,能够通过与所述数据请求的路径匹配的所述路由表中的资源路径,该过滤器将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器中;所述控制器接收所述数据请求并进行处理,最后所述服务器将所述控制器处理后的结果发送给所述的客户端。
The
在本发明的实施例中,控制器Controller处理接收的所述数据请求时,其具体的实施过程是控制器Controller将数据请求发送给服务器上的MVC框架中的模型Model。该模型Model对数据请求进行业务逻辑判断,在进行处理 的过程中可能需要提取所述服务器上的数据库,最后该模型Model将处理后的数据请求返回给所述的控制器Controller。还有,该模型Model还可以将处理后的数据请求存入到所述服务器上的数据库中。 In the embodiment of the present invention, when the controller processes the received data request, the specific implementation process is that the controller sends the data request to the model Model in the MVC framework on the server. The model Model judges the business logic of the data request, and may need to extract the database on the server during processing, and finally the model Model returns the processed data request to the controller Controller. Also, the model Model can also store the processed data request into the database on the server. the
作为本发明的一个实施例,在所述数据请求的路径与路由表中的资源路径匹配成功后,并且在该过滤器Filer将所述的数据请求传送到所述服务器上的MVC框架中相应的控制器controller中之前,可以进行该数据请求是否配置有监听器的判断。若该数据请求配置了监听器,则先执行该监听器,然后根据该监听器的信息将所述的数据请求发送给相应的控制器controller。若该数据请求没有配置监听器,则直接将该数据请求传送给相应的控制器controller。其中,该监听器可以设置有认证、日志、数据压缩、图片转换以及令牌等等应用。 As an embodiment of the present invention, after the path of the data request is successfully matched with the resource path in the routing table, and the filter Filer transmits the data request to the corresponding Before the controller is in the controller, it can be judged whether the data request is configured with a listener. If the data request is configured with a listener, the listener is executed first, and then the data request is sent to a corresponding controller according to the information of the listener. If the data request is not configured with a listener, the data request is directly sent to the corresponding controller controller. Wherein, the listener may be provided with applications such as authentication, log, data compression, image conversion, and token. the
作为本发明的另一个实施例中,当所述控制器controller接收模型Model处理后的结果之后,并且在该处理后的数据结果通过服务器返回给客户端之前,进行判断该处理后的数据结果是否配置有监听器。若配置有监听器,则先执行该监听器,然后再将处理后的数据请求返回给客户端。若没有配置监听器,则控制器controller接收模型Model处理后的结果之后,服务器直接将处理后的数据请求返回给客户端。 As another embodiment of the present invention, after the controller receives the processed result of the model Model, and before the processed data result is returned to the client through the server, it is judged whether the processed data result Configured with listeners. If a listener is configured, execute the listener first, and then return the processed data request to the client. If no listener is configured, the server will directly return the processed data request to the client after the controller receives the processed result of the Model. the
另外,值得说明的是所述服务器返回的处理后的数据请求可以是Json、XML、JSP、Free Mark以及Velocity等等形式的数据。在本发明的另一个实施例中所述服务器将处理后的结果发送给所述客户端的过程中,若需要以视图view的形式呈现给所述客户端的时候,例如JSP、Velocity和Free Mark等形式的数据,则通过所述服务器上的MVC框架中的视图view最后将处理后的结果发送给所述的客户端。其中,视图view接收控制器controller传送的处理后的数据请求,然后视图view将处理后的数据请求返回给所述的客户端。当然,若不需要以视图view的形式呈现给所述客户端的时候,则所述服务器直接将处理后的数据请求返回客户端。 In addition, it is worth noting that the processed data request returned by the server may be data in the form of Json, XML, JSP, Free Mark, and Velocity. In another embodiment of the present invention, when the server sends the processed result to the client, if it needs to be presented to the client in the form of a view, such as JSP, Velocity and Free Mark, etc. data, the processed result is finally sent to the client through the view view in the MVC framework on the server. Wherein, the view view receives the processed data request transmitted by the controller, and then the view view returns the processed data request to the client. Certainly, if it is not necessary to present to the client in the form of a view, the server directly returns the processed data request to the client. the
由此可以看出,本发明实现的基于REST的JAVA MVC系统及其数据处理方法,创造性的提出了基于REST的规范建立JAVA MVC框架,融合了REST和JAVA MVC的优点,减少了第三方包的依赖,大大降低了配置文件的时间,缩小了系统体积;而且,在将数据请求传送给控制器之前,进行判 断该数据请求是否配置有监听器,配置监听器后可以直接通过该监听器将所述的数据请求发送给相应的控制器,从而使数据请求能够快速、方便地找到并传送达相对应的控制器;在将数据请求传送给控制器之前使用监听器也使得数据请求的传送更为安全;还有,在所述控制器将处理后的数据请求通过服务器返回给客户端之前,使用监听器达到了将整个客户端数据请求的过程监视起来;与此同时,本发明采用无侵入的注解方式进行开发模式,配置更简易、项目开发周期更短、项目体积大大减小,直正的做到了跨平台、跨语言的开发;另外,后期维护成本大大降低,由于采用了Java原生低层代码和功能,使得项目更稳定、更安全、更便于维护,从而提高了Web开发效率;特别适用于中小型项目,快速开发、简易配置;最后,整个所述的基于REST的JAVA MVC系统及其数据处理方法简便、紧凑,易于实现。 From this it can be seen that the REST-based JAVA MVC system and data processing method thereof realized by the present invention creatively propose a REST-based specification to establish a JAVA MVC framework, which combines the advantages of REST and JAVA MVC and reduces the cost of third-party packages. Dependence greatly reduces the time for configuring files and reduces the size of the system; moreover, before transmitting the data request to the controller, it is judged whether the data request is configured with a listener. After the listener is configured, the listener can be directly passed The data request is sent to the corresponding controller, so that the data request can be quickly and conveniently found and transmitted to the corresponding controller; the use of the listener before the data request is transmitted to the controller also makes the transmission of the data request more efficient. For safety; Also, before the controller returns the processed data request to the client through the server, the listener is used to monitor the process of the entire client data request; meanwhile, the present invention adopts non-invasive The annotation method is used for development mode, the configuration is simpler, the project development cycle is shorter, and the project volume is greatly reduced, and the development of cross-platform and cross-language is achieved directly; in addition, the maintenance cost is greatly reduced in the later stage, due to the use of Java native low-level code and functions, making the project more stable, safer, and easier to maintain, thereby improving the efficiency of Web development; especially suitable for small and medium-sized projects, fast development, easy configuration; finally, the entire REST-based JAVA MVC system and its data The processing method is simple, compact and easy to realize. the
所属领域的普通技术人员应当理解:以上所述仅为本发明的具体实施例而已,并不用于限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。 Those of ordinary skill in the art should understand that: the above descriptions are only specific embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present invention etc., should be included within the protection scope of the present invention. the
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201310676194.2A CN103647828B (en) | 2013-12-11 | 2013-12-11 | REST-based JAVA MVC system and data processing method thereof |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201310676194.2A CN103647828B (en) | 2013-12-11 | 2013-12-11 | REST-based JAVA MVC system and data processing method thereof |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN103647828A true CN103647828A (en) | 2014-03-19 |
| CN103647828B CN103647828B (en) | 2017-01-11 |
Family
ID=50252982
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201310676194.2A Active CN103647828B (en) | 2013-12-11 | 2013-12-11 | REST-based JAVA MVC system and data processing method thereof |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN103647828B (en) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105867948A (en) * | 2016-04-26 | 2016-08-17 | 江苏物联网研究发展中心 | WEB development method based on AJAX (Asynchronous JavaScript and XML) and Spring MVC (model view controller) |
| CN106503103A (en) * | 2016-10-17 | 2017-03-15 | 济南浪潮高新科技投资发展有限公司 | A kind of lightweight REST service framework implementation method |
| CN110837359A (en) * | 2019-11-06 | 2020-02-25 | 北京小狗智能机器人技术有限公司 | MVC Web framework realized by GOLANG language |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101901163A (en) * | 2010-07-13 | 2010-12-01 | 北京世纪高通科技有限公司 | Method and device for distributing messages |
| CN102316169A (en) * | 2011-09-29 | 2012-01-11 | 北京邮电大学 | Method for realizing quick service convergence and general service platform |
| US20130160130A1 (en) * | 2011-12-20 | 2013-06-20 | Kirill Mendelev | Application security testing |
-
2013
- 2013-12-11 CN CN201310676194.2A patent/CN103647828B/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101901163A (en) * | 2010-07-13 | 2010-12-01 | 北京世纪高通科技有限公司 | Method and device for distributing messages |
| CN102316169A (en) * | 2011-09-29 | 2012-01-11 | 北京邮电大学 | Method for realizing quick service convergence and general service platform |
| US20130160130A1 (en) * | 2011-12-20 | 2013-06-20 | Kirill Mendelev | Application security testing |
Non-Patent Citations (3)
| Title |
|---|
| 左文革: "基于Java Web程序的"轻量级"MVC实现", 《图书馆自动化》 * |
| 廖雪峰: "设计REST风格的MVC框架", 《HTTP://WWW.IBM.COM/DEVELOPERWORKS/CN/JAVA/J-LO-RESTMVC/》 * |
| 杨晴雯,等: "管道、过滤器和MVC软件体系模式在J2EE中的应用", 《计算机应用研究》 * |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105867948A (en) * | 2016-04-26 | 2016-08-17 | 江苏物联网研究发展中心 | WEB development method based on AJAX (Asynchronous JavaScript and XML) and Spring MVC (model view controller) |
| CN106503103A (en) * | 2016-10-17 | 2017-03-15 | 济南浪潮高新科技投资发展有限公司 | A kind of lightweight REST service framework implementation method |
| CN110837359A (en) * | 2019-11-06 | 2020-02-25 | 北京小狗智能机器人技术有限公司 | MVC Web framework realized by GOLANG language |
Also Published As
| Publication number | Publication date |
|---|---|
| CN103647828B (en) | 2017-01-11 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11856065B2 (en) | Data transmission for service integration between a virtual private cloud and an intranet | |
| KR101877188B1 (en) | Service layer interworking using mqtt protocol | |
| KR101950122B1 (en) | Interworking light weight machine-to-machine protocol with device management protocol | |
| EP3195572B1 (en) | Systems and methods for enabling access to third party services via a service layer | |
| KR20170118815A (en) | Message Bus Service Directory | |
| JP5960186B2 (en) | Virtual channel construction system, virtual channel construction method, and virtual channel construction program | |
| CN105763619B (en) | The method and device that client and server-side are communicated | |
| CN104320396B (en) | data interaction device and method | |
| CN111901157B (en) | A k8s-based service deployment method, device, equipment, and medium | |
| WO2015196330A1 (en) | Operation method of routing device, routing device and terminal device | |
| WO2017028399A1 (en) | Communication data transmission method and system | |
| CN101303650A (en) | Function extension method and function extension system of software platform | |
| WO2015192582A1 (en) | Virtual desktop login authentication method and apparatus | |
| CN110381058B (en) | Request transmission method and device based on full-duplex communication protocol WebSocket | |
| CN103647828B (en) | REST-based JAVA MVC system and data processing method thereof | |
| WO2013120325A1 (en) | Browser-to-browser direct communication method, device and communication system | |
| CN107368334B (en) | A business plug-in interaction system and method | |
| KR20190069284A (en) | Method of converting and interworking ocf resourse of internet service, and an apparatus performing the same | |
| US20150261875A1 (en) | HTML Network Service Tags Used with Web Browsers for Controlling Network Elements | |
| WO2013185696A2 (en) | Data processing method and device | |
| CN106357781A (en) | Method and system for establishing resource service calling interface | |
| CN105516269A (en) | Application configuration method and application configuration device | |
| WO2017041550A1 (en) | Device simulator communication method and system | |
| WO2008089632A1 (en) | Communication system,device and method of registering portlets | |
| CN106301902A (en) | A kind of remote network management method based on B/S framework and system |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| CP03 | Change of name, title or address |
Address after: 1002-1, 10th floor, No.56, Beisihuan West Road, Haidian District, Beijing 100080 Patentee after: Ronglian Technology Group Co.,Ltd. Address before: 100080, Beijing, Haidian District, No. 56 West Fourth Ring Road, glorious Times Building, 10, 1002-1 Patentee before: UNITED ELECTRONICS Co.,Ltd. |
|
| CP03 | Change of name, title or address | ||
| EE01 | Entry into force of recordation of patent licensing contract |
Application publication date: 20140319 Assignee: CHINA TECHNOLOGY EXCHANGE Co.,Ltd. Assignor: Ronglian Technology Group Co.,Ltd. Contract record no.: X2021980013287 Denomination of invention: Java MVC system based on rest and its data processing method Granted publication date: 20170111 License type: Exclusive License Record date: 20211124 |
|
| EE01 | Entry into force of recordation of patent licensing contract | ||
| PE01 | Entry into force of the registration of the contract for pledge of patent right |
Denomination of invention: Java MVC system based on rest and its data processing method Effective date of registration: 20211130 Granted publication date: 20170111 Pledgee: CHINA TECHNOLOGY EXCHANGE Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2021110000080 |
|
| PE01 | Entry into force of the registration of the contract for pledge of patent right | ||
| PC01 | Cancellation of the registration of the contract for pledge of patent right |
Date of cancellation: 20230129 Granted publication date: 20170111 Pledgee: CHINA TECHNOLOGY EXCHANGE Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2021110000080 |
|
| PC01 | Cancellation of the registration of the contract for pledge of patent right | ||
| EC01 | Cancellation of recordation of patent licensing contract | ||
| EC01 | Cancellation of recordation of patent licensing contract |
Assignee: CHINA TECHNOLOGY EXCHANGE Co.,Ltd. Assignor: Ronglian Technology Group Co.,Ltd. Contract record no.: X2021980013287 Date of cancellation: 20230321 |
|
| PE01 | Entry into force of the registration of the contract for pledge of patent right |
Denomination of invention: REST based JAVA MVC system and its data processing method Effective date of registration: 20231116 Granted publication date: 20170111 Pledgee: Jining High-tech Holding Group Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2023110000482 |
|
| PE01 | Entry into force of the registration of the contract for pledge of patent right | ||
| PC01 | Cancellation of the registration of the contract for pledge of patent right |
Granted publication date: 20170111 Pledgee: Jining High-tech Holding Group Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2023110000482 |
|
| PC01 | Cancellation of the registration of the contract for pledge of patent right | ||
| PE01 | Entry into force of the registration of the contract for pledge of patent right |
Denomination of invention: JAVA MVC System Based on REST and Its Data Processing Method Granted publication date: 20170111 Pledgee: Jining High-tech Holding Group Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2025990000041 |
|
| PE01 | Entry into force of the registration of the contract for pledge of patent right | ||
| PC01 | Cancellation of the registration of the contract for pledge of patent right | ||
| PC01 | Cancellation of the registration of the contract for pledge of patent right |
Granted publication date: 20170111 Pledgee: Jining High-tech Holding Group Co.,Ltd. Pledgor: Ronglian Technology Group Co.,Ltd. Registration number: Y2025990000041 |