播放-永久使用Ebean通过ID删除帖子 [英] Play - Deleting a post by id using Ebean permanantly

查看:167
本文介绍了播放-永久使用Ebean通过ID删除帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为帖子实现删除选项!我有 model 的帖子和一个 deletePostOnly() java方法,可以使用ebean <$ permanently永久删除它c $ c> delete()函数。

I am implementing a delete option for a post! I have got model for a post and a deletePostOnly() java method for it to delete it PERMANENTLY using ebean delete() function.

但是问题是它什么也不做,也没有删除帖子。
以下是示例帖子的图片。

But the problem is that it is doing nothing and it is not deleting the post. Following is the picture of the sample post.

删除发布Java方法

public static Result deletePostOnly(Long postId) {

    //check if post can be deleted with this user
    SimplePost post = SimplePost.find.byId(postId);
    if(post == null) {
        return badRequest();
    }

    UserAccount account = Secured.getCurrentUser();
    if(!(post.getPostUserId().equals(account.getId()))) {
        return badRequest();
    }

    try {
        post.delete();        
        post.save();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return ok("ok");
}

这是 delete()正在调用的函数

public void delete() {
    Ebean.delete(this);
}

这是 save()函数

@Override
public void save() {
    super.save();
}

我也尝试过使用创建ebean查询,但这是非常不一致的(它

I have also tried using creating ebean query, but it is very inconsistent (it works sometimes & it doesn't sometimes.

有人可以告诉我我要去哪里了吗,或者可能是另一种更有效地删除此帖子的方式吗?

Can anyone please tell me where I am going wrong or may be another different way to delete this post more efficiently? I couldn't think of it!

任何帮助/建议都非常受欢迎!

Any help/suggestions much welcomed!

推荐答案

如果删除后保存了bean,则基本上是重新创建它。省去 post.save()行。

If you save your bean after having deleted it, you basically recreate it. Leave out the post.save() line.

这篇关于播放-永久使用Ebean通过ID删除帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆