Home >Web Front-end >JS Tutorial >Comment pagination written in js (not bad)_javascript skills

Comment pagination written in js (not bad)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:451055browse
Copy code The code is as follows:

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>






微客服












/


评论()






发表评论


您的评论:










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;
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn