package com.hnust.research.action;

import java.net.URLDecoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

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

import com.hnust.research.base.BaseAction;
import com.hnust.research.domain.Comment;
import com.hnust.research.domain.User;
import com.hnust.research.util.QueryHelper;
import com.opensymphony.xwork2.ActionContext;

@Controller
@Scope("prototype")
public class CommentAction extends BaseAction<Comment>{
	private String result;
	public String comment() throws Exception{
		User user=(User) ActionContext.getContext().getSession().get("user");
		
		if(user!=null){
			model.setDatetime(new Date());
			model.setUser(user);
			//为了解决ajax传值乱码
			model.setComment(URLDecoder.decode(model.getComment(),"UTF-8"));
			commentService.save(model);
			SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			result="{'result':'yes','comment':'"+model.getComment()+"','img':'"+user.getImgpath()+"','time':'"+simpleDateFormat.format(model.getDatetime())+"','username':'"+user.getUsername()+"'}";
		}else{
			result="{'result':'no'}";
		}
		return "comment";
	}
	
	public String list() throws Exception{
		QueryHelper queryHelper=new QueryHelper(Comment.class, "comment");
		queryHelper.preparePageBean(commentService, pageNum, pageSize);
		return "list";
	}
	
	public String delete() throws Exception{
		commentService.delete(model.getId());
		return "toList";
	}
	
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	
}
最近下载更多
TheOne622  LV1 2024年12月10日
1481421104  LV3 2024年11月14日
y_x_happy  LV4 2024年6月25日
educationAAA  LV11 2024年5月25日
ziv5466123  LV7 2023年12月15日
xuweiwowzy  LV5 2023年7月30日
wanglei92  LV2 2023年6月26日
hosinvm  LV7 2022年11月18日
123456781  LV4 2022年7月13日
二十一画  LV10 2022年6月25日
最近浏览更多
没有啊很开心啊  LV4 3月7日
暂无贡献等级
1481421104  LV3 2024年11月14日
是数据库  LV3 2024年10月28日
微信网友_7211237575856128 2024年10月23日
暂无贡献等级
WBelong  LV8 2024年9月19日
y_x_happy  LV4 2024年6月25日
educationAAA  LV11 2024年5月25日
kQWERTY 2024年5月4日
暂无贡献等级
12345644 2024年4月25日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友