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

网络编程 JavaScript javascript技巧 分类:[default] 更新日期: 2015-09-16
js写的分页在网上可以搜到很多的文章,在也为大家介绍一个,喜欢的的朋友可以参考下
</div>
<button style="background: #520202; border-top: none;border: 3px #520202 solid; border-radius: 2px 2px 2px 2px;-moz-border-radius: 6px; color: #FFEA00;" >上一页</button>
<button style="background: #520202; border-top: none;border: 3px #520202 solid; border-radius: 2px 2px 2px 2px;-moz-border-radius: 6px;float: right; color: #FFEA00;" >下一页</button>
<p style="background: #520202; color: #FFEA00;">第<span ></span>/<span ></span>页</p>
<h1 class="aa">评论(<span ></span>)</h1>
<hr size="5px;" color="#590303">
<div >
</div>
<h2 class="aa">发表评论</h2>
<h3 class="aa">您的评论:</h3>
<div >
<textarea rows="7" class="tex" cols="100%" ></textarea>
</div>
<button style="margin-left:80%; border-top: none;border: 3px #520202 solid; border-radius: 6px 6px 6px 6px;-moz-border-radius: 6px; color: #FFEA00; background: #520202;" >发表</button>
</div>
</body>
</html>

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<ClickComment> findClickCommentByPage(final int page, final int row) {
List<ClickComment> list = this.hibernateTemplate
.executeFind(new HibernateCallback<Object>() {
@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<ClickComment> findAllClickComment() {
return hibernateTemplate.find("from ClickComment");
}
}

struts配置
代码如下:

<package name="clickComment" extends="json-default" namespace="/">
<action name="addClickComment" method="addClickComment" class="clickCommentAction">
<result name="add" type="json">
<param name="root">map</param>
</result>
</action>
<action name="findClickCommentByPage" method="findClickCommentByPage" class="clickCommentAction">
<result name="findByPage" type="json">
<param name="root">map</param>
</result>
</action>
<action name="getTotalNum" method="getTotalNum" class="clickCommentAction">
<result name="total" type="json">
<param name="root">map</param>
</result>
</action>
<action name="updateClickComment" method="updateClickComment" class="clickCommentAction">
<result name="update" type="json">
<param name="root">map</param>
</result>
</action>
<action name="findAllClickComment" method="findAllClickComment" class="clickCommentAction">
<result name="list" type="json">
<param name="root">map</param>
</result>
</action>
<action name="deleteClickComment" method="deleteClickComment" class="clickCommentAction">
<result name="delete" type="json">
<param name="root">map</param>
</result>
</action>

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<String, Object> 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<String, Object> 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<String, Object>();
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<String, Object>();
map.put("list", clickCommentDao.findClickCommentByPage(page, row));
return "findByPage";
}
//查询评论条数 用于微信用户
public String getTotalNum(){
map = new HashMap<String, Object>();
map.put("total", clickCommentDao.getClickCommentCount());
return "total";
}
//回复评论 用于后台管理
public String updateClickComment(){
boolean isSuccess=false;
map=new HashMap<String, Object>();
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<String, Object>();
List<ClickComment> lists=clickCommentDao.findClickCommentByPage(page, rows);
List<ClickComment> 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<String, Object>();
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;
}
}

> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!

相关文章
  • HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend)
    本文主要介绍HTML5实战与剖析之触摸事件,介绍的比较详细,需要的朋友可以参考下. HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主要是触摸事件:touchstart.touchmove和touchend. ...
  • js选择器全面解析
    下面小编就为大家带来一篇js选择器全面解析.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧原生JS选择器有getElementById.getElementsByName.getElementsByTagName和getElementsByClassName这四个,下面我就一个一个介绍这四个选择器的用法. 1.getElemen ...
  • 利用ASP.NETMVC+Bootstrap搭建个人博客之打造清新分页Helper三
    利用ASP.NETMVC+Bootstrap搭建个人博客之打造清新分页Helper三
    这篇文章主要介绍了利用ASP.NET MVC+Bootstrap搭建个人博客之打造清新分页Helper三的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下0. 没有找到一款中意的分页插件,又不想使用现成的(丑到爆),所以自己动手造一个吧 先看下效果(其实也不咋滴...): 我的小站地址:我的Bootstrap小站; PS:(问博客园:为什么老是删我 ...
  • 利用ASP.NETMVC+Bootstrap搭建个人博客之praise.js点赞特效插件(二)
    这篇文章主要介绍了利用ASP.NET和MVC+Bootstrap搭建个人博客之praise.js点赞特效插件二的相关资料,需要的朋友可以参考下在上篇文章给大家介绍了利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一).接下来给大家介绍如果做个点赞插件,一起通过本文学习吧! 1. 为啥要做这个点赞插件?    praise.js是一款小 ...
  • Python中在脚本中引用其他文件函数的实现方法
    下面小编就为大家带来一篇Python中在脚本中引用其他文件函数的实现方法.小编觉得挺不错的,现在就分享给大家,也给大家做个参考.一起跟随小编过来看看吧在导入文件的时候,Python只搜索当前脚本所在的目录,加载(entry-point)入口脚本运行目录和sys.path中包含的路径例如包的安装地址.所以如果要在当前脚本引用其他文件,除了将文件放在和脚本同一目 ...
  • Jquery和BigFileUpload实现大文件上传及进度条显示
    Jquery和BigFileUpload实现大文件上传及进度条显示
    这篇文章主要介绍了Jquery和BigFileUpload实现大文件上传及进度条显示的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下实现方法:用到了高山来客 的bigfileupload组件,用高山来客的方法,弹出一个模式窗口,然后不停刷新获取进度,始终觉得体验感不好,于是想到用jquery来实现无刷新进度显示,因为提交页面后, 不能让其刷新页面 ...
猜你喜欢