DiscussDAO.java
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.appspot.cindyblog.dao;
- import java.util.List;
- import javax.persistence.EntityManager;
- import javax.persistence.Query;
- import com.appspot.cindyblog.pojo.DiscussBean;
- public class DiscussDAO extends BaseDAO{
- public boolean updateDiscuss(DiscussBean o,EntityManager em) {
- boolean b = false;
- try {
- DiscussBean d = em.find(DiscussBean.class,o.getId());
- d.setAriicle_id(o.getAriicle_id());
- d.setTitle(o.getTitle());
- d.setTime(o.getTime2());
- d.setContent(o.getContent2());
- b = true;
- } catch(Exception ex){
- ex.printStackTrace();
- }finally {
- return b;
- }
- }
- public List<DiscussBean> getDiscusses(int article_id,int start,int limit,EntityManager em) {
- List list = null;
- try{
- String query = "select from "+DiscussBean.class.getName()+" where article_id =:value order by time desc";
- list = em.createQuery(query).setFirstResult(start).setMaxResults(limit).setParameter("value", article_id).getResultList();
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- return list;
- }
- }
- public int getDiscussCount(EntityManager em,Long value) {
- int i = 0;
- try{
- String queryString = "select from "+DiscussBean.class.getName()+" where article_id =:value";
- Query query = em.createQuery(queryString);
- query.setParameter("value", value);
- List<DiscussBean> list = query.getResultList();
- if(list == null){
- i = 0;
- }else{
- i = list.size();
- }
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- return i;
- }
- }
- }