复制代码代码如下 :
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
Chemin de chaîne = request.getContextPath();
Chaîne basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ chemin + "/" ;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<tête>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<méta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>微客服</title>
<style type="text/css">
corps{
alignement du texte : centre ;
marge : 0 ;
remplissage : 0 ;
couleur : #500f60 ;
arrière-plan : url("../images/bj_4.jpg");
répétition d'arrière-plan : pas de répétition ;
pièce jointe d'arrière-plan : défilement ;
taille de l'arrière-plan : 100 % 100 % ;
overflow-x : caché ;
}
li{
type de style de liste : aucun ;
}
a:lien{
type de style de liste : aucun ;
}
img{
largeur : 100 % ;
}
#statique{
marge : 0 automatique ;
aligner le texte : gauche ;
largeur : 90 % ;
marge supérieure : 20 px ;
}
.aa{
remplissage à gauche : 16 px ;
}
#bott{
bordure : 3px #590303 solide ;
rayon de bordure : 6px 6px 6px 6px ;
-moz-border-radius : 6px ;
largeur : 90 % ;
marge gauche : 5 % ;
}
.Texas{
bordure supérieure : aucune ;
bordure inférieure : aucune ;
bordure gauche : aucune ;
bordure droite : aucune ;
arrière-plan : corrigé ;
}
</style>
</tête>
<script type="text/javascript">
$(fonction() {
var ligne = 5 ;
//动态加评论信息
fonction loadCommentInfo(page) {
$("#page").text(page);
$.ajax({
tapez : "POST",
url : "<%=basePath%>findClickCommentByPage.action",
données : "page="+page+"&row="+ligne,
succès : fonction (données) {
var liste = data.list;
var ligne = "";
$("#comments").empty();
pour ( var je = 0; je < liste.longueur; je++) {
row = "<h3><span style="color: #000; taille de police : 0,5em ; padding-left : 70 % ;/">"+list[i].time+"</span></h3>"+
"<h3 style=/"padding-left: 12px;/">"+list[i].content+"</h3>";
si(liste[i].repcontent!=null){
row+="<h3 style="padding-left: 12px; retour à la ligne : coupure de mot ; saut de mot : normal;/">回复:"+list[i].repcontent+"</h3>";
}
"<hr size=/"5px;/" color=/"#f0f/">";
$(row).appendTo($("#comments"));
}
$("#pagetag").val(page);
}
});
} ;
fonction getTotalContent() {
$.ajax({
tapez : "POST",
url : "<%=basePath%>getTotalNum.action",
succès : fonction (données) {
$("#count").text(data.total);
si(parseInt(data.total)==0){
$("#page").text(0);
}
var pagenum = parseInt(data.total/row);
$("#totalpage").text(parseInt(data.total%row==0?pagenum:pagenum+1));
},
});
}
$("#submit").click(function(){
var content = $("#content").val();
si(content==""){
alert("内容不能为空!");
retour;
}
$.post("<%=basePath%>addClickComment.action","content="+content,function(data){
si (data.success == true) {
alert("发表成功!");
$("#content").val("");
loadCommentInfo(parseInt($("#pagetag").val()));
getTotalContent();
}
});
});
$("#pre").click(function(){
var page = parseInt($("#pagetag").val());
si(page>1){
page--;
chargerCommentInfo(page);
}
});
$("#suivant").click(function(){
var page = parseInt($("#pagetag").val());
if(page<parseInt($("#totalpage").text())){
page++ ;
chargerCommentInfo(page);
}
});
window.onload = loadCommentInfo(1);
window.onload = getTotalContent();
});
</script>
<corps>
<input type="hidden" id="pagetag" value="1">
<div id="statique">
<div style="text-align: gauche; z-index: 999">
<img src="../pic/top4.jpg">
<a href="<%=basePath%>jsp/index.jsp"><img src="../pic/fan_2.png"></a>
</div>
<button style="background: #520202; border-top: none;border: 3px #520202 solid; border-radius: 2px 2px 2px 2px;-moz-border-radius: 6px; color: #FFEA00;" id="pre">上一页</button>
<button style="background: #520202; border-top: none;border: 3px #520202 solid; border-radius: 2px 2px 2px 2px;-moz-border-radius: 6px;float: droite; couleur: #FFEA00; " id="next">下一页</button>
<p style="background: #520202; color: #FFEA00;">第<span id="page"></span>/<span id="totalpage"></span>页</p>
<h1>评论(<span id="count"></span>)</h1>
<taille hr="5px;" couleur="#590303">
<div id="commentaires">
</div>
<h2>发表评论</h2>
<h3>您的评论:</h3>
<div id="bott">
<textarea rows="7" cols="100%" id="content"></textarea>
</div>
<style de bouton="margin-left:80%; border-top: none;border: 3px #520202 solid; border-radius: 6px 6px 6px 6px;-moz-border-radius: 6px; couleur: #FFEA00; arrière-plan : #520202;" id="submit">发表</button>
</div>
</corps>
</html>
dao层
复制代码代码如下 :
paquet dfml.daoImpl;
importer java.sql.SQLException ;
importer java.util.List ;
importer javax.annotation.Resource ;
importer org.hibernate.Criteria ;
importer org.hibernate.HibernateException ;
importer org.hibernate.Query ;
importer org.hibernate.Session ;
importer org.hibernate.criterion.Order ;
importer org.springframework.orm.hibernate3.HibernateCallback ;
importer org.springframework.orm.hibernate3.HibernateTemplate ;
importer org.springframework.stereotype.Component ;
importer dfml.dao.ClickCommentDao ;
importer dfml.pojo.ClickComment ;
@Composant
classe publique ClickCommentDaoImpl implémente ClickCommentDao{
privé HibernateTemplate hibernateTemplate ;
@Ressource
public void setHibernateTemplate(HibernateTemplatehibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
//添加一条评论信息
@Outrepasser
public boolean addClickComment(ClickComment clickComment) {
booléen isSuccess = faux ;
essayer {
hibernateTemplate.save(clickComment);
estSuccès = vrai ;
} attraper (Exception e) {
estSuccès = faux ;
e.printStackTrace();
}
return isSuccès ;
}
//分页查找评论信息
@SuppressWarnings("non coché")
@Outrepasser
public List<ClickComment> findClickCommentByPage (page int finale, ligne int finale) {
List<ClickComment> list = this.hibernateTemplate
.executeFind(nouveau HibernateCallback<Object>() {
@Outrepasser
Objet public doInHibernate (session de session)
lance HibernateException, SQLException {
Critères c = session.createCriteria(ClickComment.class);
c.setFirstResult((page - 1) * ligne);
c.setMaxResults(ligne);
c.addOrder(Order.desc("heure"));
return c.list();
}
});
liste de retour ;
}
//得到评论的个数
@SuppressWarnings({ "non coché", "rawtypes" })
@Outrepasser
public Long getClickCommentCount() {
final String hql = "select count(*) from ClickComment";
Résultat long = nul ;
result = (Long) hibernateTemplate.execute(new HibernateCallback() {
Objet public doInHibernate (Session arg0)
lance HibernateException, SQLException {
Requête de requête = arg0.createQuery(hql);
return query.uniqueResult();
}
});
renvoyer le résultat ;
}
//更新评论信息
@Outrepasser
public boolean updateClickComment(ClickComment clickComment) {
booléen isSuccess=false ;
essayer {
hibernateTemplate.update(clickComment);
estSuccès=true ;
} attraper (Exception e) {
e.printStackTrace();
estSuccès=false ;
}
return isSuccès ;
}
//根据id查找评论信息
@Outrepasser
public ClickComment findClickCommentById (int id) {
return (ClickComment) hibernateTemplate.find("from ClickComment où id = ?",
identifiant).get(0);
}
//删除评论信息
@Outrepasser
public boolean deleteClickComment(ClickComment clickComment) {
booléen isSuccess=false ;
essayer {
hibernateTemplate.delete (cliquez sur Commentaire);
estSuccès=true ;
} attraper (Exception e) {
e.printStackTrace();
estSuccès=false ;
}
return isSuccès ;
}
//查询所有的评论
@SuppressWarnings("non coché")
@Outrepasser
public List<ClickComment> findAllClickComment() {
return hibernateTemplate.find("from ClickComment");
}
}
entretoises配置
复制代码代码如下 :
<package name="clickComment" extends="json-default" namespace="/">
<action name="addClickComment" méthode="addClickComment">
<result name="add" type="json">
<param name="root">carte</param>
</résultat>
</action>
<action name="findClickCommentByPage" méthode="findClickCommentByPage">
<result name="findByPage" type="json">
<param name="root">carte</param>
</résultat>
</action>
<action name="getTotalNum" méthode="getTotalNum">
<result name="total" type="json">
<param name="root">carte</param>
</résultat>
</action>
<action name="updateClickComment" méthode="updateClickComment">
<result name="update" type="json">
<param name="root">carte</param>
</résultat>
</action>
<action name="findAllClickComment" méthode="findAllClickComment">
<result name="list" type="json">
<param name="root">carte</param>
</résultat>
</action>
<action name="deleteClickComment" méthode="deleteClickComment">
<result name="delete" type="json">
<param name="root">carte</param>
</résultat>
</action>
action
复制代码代码如下 :
paquet dfml.action ;
importer java.sql.Date ;
importer java.text.SimpleDateFormat ;
importer java.util.HashMap ;
importer java.util.List ;
importer java.util.Map ;
importer javax.annotation.Resource ;
importer org.springframework.context.annotation.Scope ;
importer org.springframework.stereotype.Component ;
importer com.opensymphony.xwork2.ActionSupport ;
importer dfml.dao.ClickCommentDao ;
importer dfml.pojo.Activity ;
importer dfml.pojo.ClickComment ;
@Component("cliquezCommentAction")
@Scope("prototype")
la classe publique ClickCommentAction étend ActionSupport{
privé statique final long serialVersionUID = 1L ;
ClickCommentDao privé clickCommentDao ;
carte privée Map<String, Object> ;
contenu de la chaîne privée ; // 评论内容
private String repcontent ; // 回复评论
page internationale privée ;
ligne intérieure privée ;
lignes entières privées ;
identifiant international privé ;
public void setId (int id) {
this.id = identifiant;
}
public Map<String, Objet> getMap() {
carte de retour ;
}
@Ressource
public void setClickCommentDao(ClickCommentDao clickCommentDao) {
this.clickCommentDao = clickCommentDao;
}
public void setContent (contenu de la chaîne) {
this.content = contenu ;
}
public void setRepcontent (String repcontent) {
this.repcontent = repcontent;
}
public void setPage (int page) {
cette.page = page ;
}
public void setRow(int ligne) {
this.row = ligne;
}
public void setRows (int lignes) {
this.rows = lignes ;
}
//添加评论 用于微信用户
chaîne publique addClickComment() {
booléen isSuccess = faux ;
map = new HashMap<String, Object>();
ClickComment clickComment = new ClickComment();
Format SimpleDateFormat = new SimpleDateFormat("aaaa-MM-jj HH:mm:ss");
clickComment.setTime(format.format(new Date(System.currentTimeMillis())));
clickComment.setContent(content);
essayer {
isSuccess = clickCommentDao.addClickComment(clickComment);
} attraper (Exception e) {
estSuccès = faux ;
e.printStackTrace();
}
map.put("succès", isSuccess);
renvoie "ajouter" ;
}
//分页查找评论 用户微信用户
chaîne publique findClickCommentByPage() {
map = new HashMap<String, Object>();
map.put("liste", clickCommentDao.findClickCommentByPage(page, ligne));
renvoie « findByPage » ;
}
//查询评论条数 用于微信用户
chaîne publique getTotalNum(){
map = new HashMap<String, Object>();
map.put("total", clickCommentDao.getClickCommentCount());
renvoyer « total » ;
}
//回复评论 用于后台管理
chaîne publique updateClickComment(){
booléen isSuccess=false ;
map=new HashMap<String, Object>();
ClickComment clickComment =clickCommentDao.findClickCommentById(id);
si (cliquez sur Comment ! = null) {
clickComment.setRepcontent(repcontent);
isSuccess=clickCommentDao.updateClickComment(clickComment);
}
map.put("succès", isSuccess);
renvoie "mise à jour" ;
}
//查询所有评论 用于后台管理
chaîne publique findAllClickComment(){
map=new HashMap<String, Object>();
List<ClickComment> lists=clickCommentDao.findClickCommentByPage(page, lignes) ;
List<ClickComment> listss=clickCommentDao.findAllClickComment();
map.put("lignes", listes);
map.put("total", listss.size());
map.put("liste", listess);
renvoie "liste" ;
}
//删除评论 用于后台管理
chaîne publique deleteClickComment(){
booléen isSuccess=false ;
map=new HashMap<String, Object>();
ClickComment clickComment =clickCommentDao.findClickCommentById(id);
si (cliquez sur Comment ! = null) {
isSuccess=clickCommentDao.deleteClickComment(clickComment);
}
map.put("succès", isSuccess);
renvoie "supprimer" ;
}
}
pojo
复制代码代码如下 :
paquet dfml.pojo ;
importer java.io.Serialisisable ;
importer javax.persistence.Entity ;
importer javax.persistence.GeneratedValue ;
importer javax.persistence.Id ;
//评论表
@Entité
la classe publique ClickComment implémente Serialisable{
privé statique final long serialVersionUID = 1L ;
Identifiant entier privé ;
temps de chaîne privé ; // 评论时间
contenu de la chaîne privée ; // 评论内容
nom de chaîne privé ; // 评论人
repcontent de chaîne privée ;//回复评论
@Identifiant
@Valeur générée
public entier getId() {
renvoyer l'identifiant ;
}
public void setId (identifiant entier) {
this.id = identifiant;
}
chaîne publique getRepcontent() {
renvoyer le contenu ;
}
public void setRepcontent (String repcontent) {
this.repcontent = repcontent;
}
chaîne publique getTime() {
heure de retour ;
}
public void setTime (heure de la chaîne) {
this.time = heure ;
}
chaîne publique getContent() {
renvoyer du contenu ;
}
public void setContent (contenu de la chaîne) {
this.content = contenu ;
}
chaîne publique getName() {
renvoyer le nom ;
}
public void setName (nom de la chaîne) {
this.name = nom ;
}
}