ArticleDAO.java
资源名称:cindyblog.rar [点击查看]
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.appspot.cindyblog.dao;
- import java.util.List;
- import javax.persistence.EntityManager;
- import com.appspot.cindyblog.pojo.ArticleBean;
- public class ArticleDAO extends BaseDAO{
- public List<ArticleBean> getArticles(String type,int start,int limit,EntityManager em) {
- List list = null;
- try{
- if(!em.isOpen()){
- em.joinTransaction();
- }
- String query = "select from "+ArticleBean.class.getName()+" where type =:name order by time desc";
- list = em.createQuery(query).setFirstResult(start).setMaxResults(limit).setParameter("name", type).getResultList();
- }catch(Exception ex){
- ex.printStackTrace();
- }finally{
- return list;
- }
- }
- public boolean addSayCount(Long id,EntityManager em) {
- boolean b = false;
- try {
- ArticleBean o = em.find(ArticleBean.class, id);
- int count = o.getSayCount();
- o.setSayCount(++count);
- b = true;
- }catch(Exception ex){
- ex.printStackTrace();
- } finally {
- return b;
- }
- }
- public boolean updateArticle(ArticleBean o,EntityManager em) {
- boolean b = false;
- try {
- ArticleBean a = em.find(ArticleBean.class,o.getId());
- a.setTitle(o.getTitle());
- a.setType(o.getType());
- a.setTime(o.getTime2());
- a.setContent(o.getContent2());
- b = true;
- }catch(Exception ex){
- ex.printStackTrace();
- } finally {
- em.flush();
- return b;
- }
- }
- }