Use Play in 10 minutes! Implement a Blog on GAE

Source: Internet
Author: User

This is because I saw an article "Play!" on JavaEye! Run GAE and test GAE. It discusses a new Java On Rails framework from Play in France! Http://www.playframework.org /). I have probably read the introduction of this framework, which is indeed excellent. For example, cool features:

  • Bind an HTTP parameter to a Java method parameter: that is to say, you can directly call the method in Controller on the URL;
  • Redirect to an action by simply calling the corresponding Java method: this does not need to be parsed;
  • Don't Repeat Yourself when passing Java objects to templates: that is, to transmit data from the controller to the View, you do not need to put the object in the map. It can be like: render (tititile, article, user); this is the use of dynamic parameters in Java 5;
  • Straightforward file upload management;
  • Distribute an application to several JVMs without processing ing anything;
  • Fix the bug and hit Reload: This is invincible, that is to say, after modifying the program, directly reload the program. the framework automatically compiles the program because the framework contains a Container, so we can do this. This is a bit like dynamic Java, saving a lot of trouble in debugging;
  • In addition, multiple in INS can be used.

I have probably read this framework, and I feel pretty good, but the main content discussed in that article is Play! Some problems of integration in GAE. This framework has a very simple Blog program, so it cannot be deployed on GAE. It is easy to understand that GAE has castrated JDK and does not provide complete support for JPA. I have been applying for a GAE account for a long time, but I have never played it. I just want to study it together.

In fact, the main limitations of GAE are:

 
 
  1. posts.remove(post);  
  2. Collections.reverse(posts); 

It cannot be used. You need to use it in other collections or sort and filter it during Query. This restriction is not troublesome, but it is not suitable for the idea of xxx on rails. It would not be unfamiliar if J2EE was first introduced. The Model defines the several items and directly operates the database, that is, the PO we are talking about. In traditional J2EE, PO cannot be operated on the Contrioller layer, the following data needs to be converted to VO before it can be moved to View ~ This is the DTO mode. Apache beanutil can do this, but this is just an example. You just need to setter and getter... Here is a solution: Play! Create a vo package, create a PostVo, and use the following code to replace the above two sentences,

 
 
  1. List<Post> posts = Post.findAll();  
  2. Iterator<Post> postIt = posts.iterator();  
  3. List<PostVo> otherPosts = new ArrayList<PostVo>();  
  4. while (postIt.hasNext()) {  
  5.       Post postItem = postIt.next();  
  6.       if (postItem.id.longValue() != id.longValue()) {  
  7.           PostVo postVo = new PostVo();  
  8.           postVo.setId(postItem.id);  
  9.           postVo.setTitle(postItem.title);  
  10.           postVo.setContent(postItem.content);  
  11.           postVo.setDate(postItem.date);  
  12.           otherPosts.add(postVo);  
  13.      }  
  14. }  
  15.       Collections.reverse(otherPosts); 

Of course, otherPosts should be used in the view to replace posts, and otherPosts can be iterated ~

After testing, Blog that routine can run up, you can test through this URL: http://laynezone.appspot.com

Summary:

Play! I like this framework very much. It is rare to see a similar quick framework in Java. If applicable, it is worth considering. In addition, GAE imposes a lot of limitations on the persistence part, but it is understandable that the persistence structure at the bottom of Google is not a relational model. It is good to implement JPA to this degree ~

Since the objective reasons cannot be changed, we can adapt ourselves to it. After all, withod RMDB has been shouting for a long time. In fact, as long as the concept changes slightly, it will be okay ~

Because, I see GAE and Play! The time for two things is today Friday. After work, I went home from work to Bahan with a meal, and now I haven't studied Play for less than 1 hour! The source code, what is said, is inevitably wrong, please communicate with each other ~

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.