...评论、转发功能如何实现2、搜索框功能 求代码谢谢
发布网友
发布时间:2024-04-09 17:38
我来回答
共1个回答
热心网友
时间:2024-04-10 14:11
//点赞
public Great findGreat(Integer aid, Integer uid) {
String hql="from Great where aid=? and uid=? ";
List<Great> list = this.getHibernateTemplate().find(hql,aid,uid);
if(list!=null && list.size()>0){
this.getHibernateTemplate().delete(list.get(0));
Answer answer=this.getHibernateTemplate().get(Answer.class,aid);
answer.setAgreat(answer.getAgreat()-1);
this.getHibernateTemplate().update(answer);
return null;
}
else {
Great great = new Great();
Answer answer2=this.getHibernateTemplate().get(Answer.class,aid);
great.setAnswer(answer2);
User user=this.getHibernateTemplate().get(User.class, uid);
great.setUser(user);
this.getHibernateTemplate().save(great);
answer2.setAgreat(answer2.getAgreat()+1);
this.getHibernateTemplate().update(answer2);
return null;
}
}