package com.admintwo.action; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.admintwo.model.pojo.CommentsUserLabels; import com.admintwo.model.pojo.UserCommentsResources; import com.admintwo.service.CommentsService; import com.admintwo.util.GsonUtils; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; /** * @Title: Comments * @Description: 该类用于处理资源操作 * @author 徐江飞 * @date 2017年3月18日 下午4:29:14 * @version V1.0 */ @Controller("comments") @Scope("prototype") public class Comments extends ActionSupport implements ModelDriven<com.admintwo.model.Comments> { private static final long serialVersionUID = 1L; private com.admintwo.model.Comments comments = new com.admintwo.model.Comments(); @Autowired private CommentsService commentsService; @Override public com.admintwo.model.Comments getModel() { return comments; } /** * 该方法用于ajax根据资源id,获取资源所有信息 * * @throws Exception */ public void getCommentsByResources_id() throws Exception { System.out.println("====comments/getCommentsByResources_id获取资源id:" + comments.getResources_id()); List<CommentsUserLabels> commentsUserLabelsList = commentsService.getCommentsByResources_id(comments.getResources_id()); System.out.println("====comments/comments.getResources_id()根据资源id获取所有评论信息:" + commentsUserLabelsList); returnJson(commentsUserLabelsList); } /** * 该方法用于ajax获取某个用户前10条评论 * * @throws Exception */ public void getTenCommentsByUser_id() throws Exception { System.out.println("====comments/getTenCommentsByUser_id获取用户id:" + comments.getUser1_id()); List<UserCommentsResources> ucrss = commentsService.getCommentsResourcesByUser_id(comments.getUser1_id()); System.out.println("====comments/comments.getTenCommentsByUser_id()根据资源id获取最近10条评论信息:" + ucrss); returnJson(ucrss); } /** * 该方法用于返回json * * @param obj * @throws Exception */ public void returnJson(Object obj) throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.print(GsonUtils.toJson(obj)); out.flush(); out.close(); return; } }
![](https://static.zuidaima.com/resource/img/heart_ico.png)
jlmarket LV22
2022年6月14日
buchifanqie LV2
2022年3月22日
陈王子 LV12
2021年10月25日
哎呀 LV1
2021年5月15日
取名字是的头疼事 LV2
2021年3月15日
xindong LV12
2021年3月2日
羞羞小子 LV13
2021年2月5日
德莱文 LV15
2021年1月24日
fbwieuhilkws LV1
2021年1月8日
今天的月白很菜 LV2
2020年12月24日
![](https://static.zuidaima.com/resource/img/cattle_ico.png)
12345644
4月25日
暂无贡献等级
爱吃零食 LV1
2023年11月2日
2036495585 LV9
2023年9月18日
sdl924 LV1
2023年5月28日
微信网友_6494655433838592
2023年5月28日
暂无贡献等级
aobiym
2023年3月26日
暂无贡献等级
hesu2020 LV1
2023年3月18日
kevinkg LV12
2023年2月27日
xiaozhilei
2023年2月22日
暂无贡献等级
zhiwei0127 LV1
2022年12月14日