Front Tiny Quick start service development and tiny Quick start web Interface Rapid development Practice, that is, the development of services and interface is not a problem, it is obvious to do a complete system is not enough, so there must be a control layer, before the entire process can be opened.
The control layer acts as a collaborative role between the interface and the service. The controller receives the user input information from the interface layer, then invokes the service to perform the specific processing, and passes the final result back to the interface layer for rendering.
The control layer in the tiny framework can be written in many ways:
- Integrated struts or other solutions to complete
- Follow the tiny framework's requirements code to complete
- Complete by Tiny page flow
The integration of struts and other scenarios is no longer described here, only in the way that is achieved through the tiny framework:
I. Writing control layer logic through code 1. code example
- @Controller ()
- public class Helloaction implements webcontextaware{
- Private Webcontext Webcontext;
- public void SetContext (Webcontext webcontext) {
- This.webcontext = Webcontext;
- }
- @RequestMapping (value={"/hellobymvc.do"})
- @View (value= "/helloworld/helloresult.page")
- public void Sayhellomethod (String name) {
- if (name = = null) {
- name = "World";
- }
- Webcontext.put ("Result", String.Format ("Hello,%s", name));
- }
- }
Copy Code
Explain
@Controller () indicates that the class is a class of control layers.
ImplementsWebcontextaware says the class is going to be injected into the webThe context object.
@RequestMapping (value={"/hellobymvc.do"}) represents a response to a/hellobymvc.do request, note that this can have multiple values.
The @View (value= "/helloworld/helloresult.page") indicates that the execution is complete and then goes to the/helloworld/helloresult.page page for rendering.
Webcontext, the web context, is an important class in the tiny web framework for placing various kinds of data on it.
You can think of it as an image map, and you can keep stuffing it in and out of it, which is visible in the presentation layer.
Of course, for the above so simple class, actually do not implement the Webcontextaware interface, this time the wording is as follows:
- @Controller ()
- public class Helloaction {
- @ResultKey (value = "Result")
- @RequestMapping (value={"/hellobymvc.do"})
- @View (value= "/helloworld/helloresult.page")
- public string Sayhellomethod (string name) {
- if (name = = null) {
- name = "World";
- }
- Return String.Format ("Hello,%s", name);
- }
- }
Copy Code
Relatively speaking, it is simpler than the one above, but the only limitation is that only one object is returned.
- @ResultKey (value= "users")
- @RequestMapping (value={"/crud/service/tinydb/list.page"})
- Public list<bean> queryusers (@ServiceParameter (name = "TUser") Bean TUser) throws Exception {
- bean[] Beans = Operator.getbeans (TUser);
- if (beans! = null) {
- return arrays.aslist (beans);
- }
- return null;
- }
Copy Code
of course, the incoming parameter does not have to be a simple type, and the object is also allowed.
2. Summary
Through annotations, it is convenient to define the processing logic of the control layer in the common Java class, the steps:
- add on Class @Controller Annotations
- Adding @requestmapping Annotations to methods
- If there is a return value, it can be returned by injecting an Webcontext object, or it can be done by @resultkey annotations, but @resultkey can only put the return value of the method into the context with the specified key.
Question: What if the control layer processing method requires an object?
- If you conform to the naming conventions of the tiny framework, everything is done automatically by the framework.
- If you do not conform to the naming conventions of the tiny framework, please inject webcontext objects and assemble them yourself.
Second, write control layer through page Flow 1. Control layer Complete all functions
Of course, the HelloWorld function is too simple, it can even be done directly in the control layer.
104025_4n0j_1245989.jpg (3.57 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
While this is not a logical problem for the computer, it also gives the correct results, but in practice it is problematic because the business logic should not be done at the control level.
Therefore, the above approach is wrong and is not recommended.
2. Business flow and page flow separation
So the right thing to do is write a business flow:
104909_ikvk_1245989.jpg (23.04 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
The process is written, and then you can write a page flow:
130035_23u4_1245989.jpg (26.72 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
Of course, it is not necessarily a line, it can also be complex, such as:
134906_htao_1245989.jpg (11.13 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
Page flow as long as a service is invoked, the result of the service is automatically placed in the context because the service is finished, so no additional processing is required by default.
3. Summary
Through the way of page flow, there is a very clear page processing logic display, easier to understand the business process. Because you don't have to write a program, you don't have to worry about the programmer adding some dangerous code in it (which is strictly prevented in some particular industry), the process is documentation, and the document can be quickly generated.
There are already many page flow components in the tiny framework, and of course support for the passionate customization of your add-ons, which involves the development of process components and is not explained in detail in this section.
4. Document Generation
First step: Select a wizard
131500_3z8f_1245989.jpg (36.22 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
Step two Select the document to be generated
131516_edzv_1245989.jpg (41.57 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
Then, just look at the generated document.
131527_d88u_1245989.jpg (60.34 KB, download number: 0)
Download attachments
2015-5-27 21:51 Upload
The technical manager can fully understand the results of the program execution and the programmer's completion by looking at the document.
It seems a bit overreaching oh, next time focus on the process orchestration related things.
Summary
The control layer of the tiny framework provides flexible and diverse writing methods, such as automatic assembly of objects, data validation, code writing control layer, and programming control layer of process arrangement. Really frees programmers from the intricacies of their work and only does what they need to do.
At this point, the main four sections of the tiny QuickStart have been discussed in the past, and the following is:
Tiny Quick Start service development
Tiny Quick Start web Interface Rapid development Practice
Tiny Quick Start Control layer development
Tomorrow will be the preparation of tiny quick Start process development , please look forward to
Tiny development of control layer for quick start