首页 > web前端 > js教程 > 正文

js写的评论分页(还不错)_javascript技巧

WBOY
发布: 2016-05-16 17:07:45
原创
1031 人浏览过
复制代码 代码如下:

pageEncoding="utf-8"%>
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>






微客服







js写的评论分页(还不错)_javascript技巧
js写的评论分页(还不错)_javascript技巧



/


评论()






发表评论


您的评论:










dao层
复制代码 代码如下:

package dfml.daoImpl;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import dfml.dao.ClickCommentDao;
import dfml.pojo.ClickComment;

@Component
public class ClickCommentDaoImpl implements ClickCommentDao{

private HibernateTemplate hibernateTemplate;

@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
//添加一条评论信息
@Override
public boolean addClickComment(ClickComment clickComment) {
boolean isSuccess = false;
try {
hibernateTemplate.save(clickComment);
isSuccess = true;
} catch (Exception e) {
isSuccess = false;
e.printStackTrace();
}
return isSuccess;
}
//分页查找评论信息
@SuppressWarnings("unchecked")
@Override
public List findClickCommentByPage(final int page, final int row) {
List list = this.hibernateTemplate
.executeFind(new HibernateCallback() {
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria c = session.createCriteria(ClickComment.class);
c.setFirstResult((page - 1) * row);
c.setMaxResults(row);
c.addOrder(Order.desc("time"));
return c.list();
}
});
return list;
}
//得到评论的个数
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Long getClickCommentCount() {
final String hql = "select count(*) from ClickComment";
Long result = null;
result = (Long) hibernateTemplate.execute(new HibernateCallback() {
public Object doInHibernate(Session arg0)
throws HibernateException, SQLException {
Query query = arg0.createQuery(hql);
return query.uniqueResult();
}
});
return result;
}
//更新评论信息
@Override
public boolean updateClickComment(ClickComment clickComment) {
boolean isSuccess=false;
try {
hibernateTemplate.update(clickComment);
isSuccess=true;
} catch (Exception e) {
e.printStackTrace();
isSuccess=false;
}
return isSuccess;
}
//根据id查找评论信息
@Override
public ClickComment findClickCommentById(int id) {
return (ClickComment) hibernateTemplate.find("from ClickComment where id = ?",
id).get(0);
}
//删除评论信息
@Override
public boolean deleteClickComment(ClickComment clickComment) {
boolean isSuccess=false;
try {
hibernateTemplate.delete(clickComment);
isSuccess=true;
} catch (Exception e) {
e.printStackTrace();
isSuccess=false;
}
return isSuccess;
}
//查询所有的评论
@SuppressWarnings("unchecked")
@Override
public List findAllClickComment() {
return hibernateTemplate.find("from ClickComment");
}

}

struts配置
复制代码 代码如下:




map




map




map




map




map




map



action
复制代码 代码如下:

package dfml.action;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

import dfml.dao.ClickCommentDao;
import dfml.pojo.Activity;
import dfml.pojo.ClickComment;

@Component("clickCommentAction")
@Scope("prototype")
public class ClickCommentAction extends ActionSupport{

private static final long serialVersionUID = 1L;

private ClickCommentDao clickCommentDao;
private Map map;
private String content;// 评论内容
private String repcontent;// 回复评论
private int page;
private int row;
private int rows;
private int id;
public void setId(int id) {
this.id = id;
}
public Map getMap() {
return map;
}
@Resource
public void setClickCommentDao(ClickCommentDao clickCommentDao) {
this.clickCommentDao = clickCommentDao;
}
public void setContent(String content) {
this.content = content;
}
public void setRepcontent(String repcontent) {
this.repcontent = repcontent;
}
public void setPage(int page) {
this.page = page;
}
public void setRow(int row) {
this.row = row;
}
public void setRows(int rows) {
this.rows = rows;
}
//添加评论 用于微信用户
public String addClickComment() {
boolean isSuccess = false;
map = new HashMap();
ClickComment clickComment = new ClickComment();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
clickComment.setTime(format.format(new Date(System.currentTimeMillis())));
clickComment.setContent(content);
try {
isSuccess = clickCommentDao.addClickComment(clickComment);
} catch (Exception e) {
isSuccess = false;
e.printStackTrace();
}
map.put("success", isSuccess);
return "add";
}
//分页查找评论 用户微信用户
public String findClickCommentByPage() {
map = new HashMap();
map.put("list", clickCommentDao.findClickCommentByPage(page, row));
return "findByPage";
}
//查询评论条数 用于微信用户
public String getTotalNum(){
map = new HashMap();
map.put("total", clickCommentDao.getClickCommentCount());
return "total";
}
//回复评论 用于后台管理
public String updateClickComment(){
boolean isSuccess=false;
map=new HashMap();
ClickComment clickComment =clickCommentDao.findClickCommentById(id);
if(clickComment!=null){
clickComment.setRepcontent(repcontent);
isSuccess=clickCommentDao.updateClickComment(clickComment);
}
map.put("success", isSuccess);
return "update";
}
//查询所有评论 用于后台管理
public String findAllClickComment(){
map=new HashMap();
List lists=clickCommentDao.findClickCommentByPage(page, rows);
List listss=clickCommentDao.findAllClickComment();
map.put("rows", lists);
map.put("total", listss.size());
map.put("list", listss);
return "list";
}
//删除评论 用于后台管理
public String deleteClickComment(){
boolean isSuccess=false;
map=new HashMap();
ClickComment clickComment =clickCommentDao.findClickCommentById(id);
if(clickComment!=null){
isSuccess=clickCommentDao.deleteClickComment(clickComment);
}
map.put("success", isSuccess);
return "delete";
}


}

pojo
复制代码 代码如下:

package dfml.pojo;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

//评论表
@Entity
public class ClickComment implements Serializable{


private static final long serialVersionUID = 1L;
private Integer id;
private String time;// 评论时间
private String content;// 评论内容
private String name;// 评论人
private String repcontent;//回复评论



@Id
@GeneratedValue
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
public String getRepcontent() {
return repcontent;
}
public void setRepcontent(String repcontent) {
this.repcontent = repcontent;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板