[Original] jFinal Study Notes (01) Hello World, jfinal Study Notes

Source: Internet
Author: User

[Original] jFinal Study Notes (01) Hello World, jfinal Study Notes

JFinal is a very good Lightweight Framework. In theory, you can get started with the framework documentation. However, if I do not understand Java, I still need to explore it at 1.1 points. This series of study notes may be the simplest and most foolish jFinal study notes in history.

 

1. Preparation of development tools:

① JDK 1.7.0 _ 65: if you do not know how to configure it after installation, you can view the JDK settings article under the Java classification.

② Myeclipse 8.5: Because Java IDE is unfamiliar, I chose this powerful tool to integrate various functions.

JFinal framework file: jetty-server-8.1.8.jar, jfinal-1.8-bin.jar these two jar packages is enough

2. Development Environment Construction:

1. Create a web project named jfinal_helloworld.

② Copy the two jar packages prepared in front to the lib under the WEB-INF under WebRoot, copy it in, you will see the Referenced Libraries also appeared under the two jar packages, the development environment is now ready. Jetty is used as the web container.

 

3. Start encoding:

① Set web. xml

Some Web. xml files in Java web engineering are like the web. config file in asp.net. Some settings are planned here.

Both the filter node and the filter-mapping node are added. Note that the param-value is the planned package name + configuration class name, which must be consistent during subsequent creation, otherwise, the configuration class cannot be found. The/* written in url-pattern naturally represents any matching.

② Create a package and configure the class. The name must be the same as the name planned in the web. xml file! Therefore, the package name is demo, and the configuration class name is DemoConfig. when the package is created, it is inherited from the JFinalConfig class.

After the method is created, the class file we can see should be like this. Here I show the function of the method in the form of annotations. The method names are very clear and clear at a glance.

③ Compile constant value and route content

In the configConstant method, enter me. setDevMode (true); // set the development mode to true.

Write me. add ("/hello", HelloController. class) in the configRoute method );

An error will be prompted when writing the route content, because the HelloController class has not been created yet. It doesn't matter. Just wait for it to be created. In other words, the write method of routing is similar. This method is similar to asp.net mvc or node. js is quite like it, which means it is quite clear. Find the HelloController controller class when there is a "path/hello" request in the url.

④ Write Controllers

Create a class HelloController under the demo package, and pay attention to inheriting from the Controller class.

Then write an index method in this control class.

The rendering text method renderText () Outputs "Hello jFinal World !"

Since then, the Code has been completed. Is it very simple? I have not written a few words.

4. Start running:

As shown in

Click to display

Click "OK" and then run it on the myeclipse console.

Open the browser and enter "localhost/hello ".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.