hibernate 中根据id删除一条记录的语句 - Cultivate
qid | name | like | content |
1 | A | 1 | the first text |
2 | B | 2 | the Second text |
1 | C | 3 | the Third text |
如上表所示,当我们需要某个qid执行删除操作时,可以按照如下语句进行执行
1 String hql="from bbsLikes b where b.qid=(:ID)"; 2 String[] paramName={"ID"}; 3 Object[] value={qid}; 5 List list = this.getHibernateTemplate().findByNamedParam(hql, paramName, value); 6 if(!list.isEmpty()){ 7 this.getHibernateTemplate().deleteAll(list); 8 return true; 9 } 10 return false; 11 }