Web App Project,需要帮助

时间:2014-02-14 21:47:22

标签: eclipse web

有人可以帮助,我在大学的第一年,我坚持我的网络开发项目。在我的博客网页上,我有一个帖子列表,我需要按时排列(首先是新帖)。我们刚刚在编程课程中开始使用arraylists但我们还没有介绍如何对它们进行排序

将PLAY框架用于包含模型,控制器,视图和路径的项目。我在models文件夹中有一个Post Class,在控制器中有一个Blog Class,如下所示

package models;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity

public class Post extends Model
{
 public String title;
 @Lob
 public String content;

@OneToMany
 public List<Comment> comments = new ArrayList<Comment>();
 public String comment;

public Post(String title, String content)
{
 this.title = title;
 this.content = content;

}

 public String toString()
{
  return title;
} 


}


package controllers;

import java.util.List;

import models.Message;
import models.Post;
import models.User;
import play.Logger;
import play.mvc.Controller;

public class Blog  extends Controller
{
 public static void index()
 {
  User user = Accounts.getLoggedInUser();
  render(user);
 }

 public static void newPost(String title, String content)
 {
  User user = Accounts.getLoggedInUser();

  Post post = new Post (title, content);
  post.save();
  user.posts.add(post);
  user.save();

  Logger.info ("title:" + title + " content:" + content);
  index();
  }

  public static void deletePost(Long postid)
  {    
   User user = Accounts.getLoggedInUser(); 

   Post post = Post.findById(postid);
   user.posts.remove(post);

   user.save();
   post.delete();

   index();
  }


  } 

这是显示已发布帖子的HTML代码

    <section class="ui stacked segment">
     <h4 class="ui inverted blue block header">Display Posts</h4>

      #{list items:user.posts, as:'post'}

       <h5 class="ui inverted green block header"></h5>
   <a href ="/blog/viewpost/${post.id}"><i class="external url icon">${post.title}</a>          
      #{/list}
     </section> 

我完全迷失在java部分并且已经多次尝试使其工作崩溃,任何帮助都将非常感激

0 个答案:

没有答案