package cn.com.mk.controller;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import cn.com.mk.common.base.BaseController;
import cn.com.mk.common.bean.BlogPageBean;
import cn.com.mk.common.bean.CollectionPageBean;
import cn.com.mk.common.bean.CommentPageBean;
import cn.com.mk.common.bean.JuBaoDetailPageBean;
import cn.com.mk.common.bean.ReportPageBean;
import cn.com.mk.common.bean.Result;
import cn.com.mk.common.date.DateUtil;
import cn.com.mk.common.function.DataHelpConstant;
import cn.com.mk.domain.Blog;
import cn.com.mk.domain.Collection;
import cn.com.mk.domain.Comment;
import cn.com.mk.domain.Friend;
import cn.com.mk.domain.Report;
import cn.com.mk.domain.Userinfo;
import cn.com.mk.domain.Zan;
import cn.com.mk.service.ISimpleDefaultService;
@Controller
@RequestMapping("/blog")
public class BlogController extends BaseController {
@Autowired
private ISimpleDefaultService iSimpleDefaultService;
MultipartFile[] fileArray = null;
@RequestMapping(value="/publish", method=RequestMethod.POST)
public String publish(@RequestParam(value = "uploadImage") MultipartFile[] fileArray, HttpServletRequest
request, HttpSession session) throws IOException{
int userid = Integer.parseInt(session.getAttribute(DataHelpConstant.SESSION_USER.USER_ID).toString());
Result result = new Result();
String content = request.getParameter("content");
Blog blog = new Blog();
String accesspath = request.getContextPath();
if (null != fileArray){
content += "<br>";
String rootPath = request.getSession().getServletContext().getRealPath("/")+File.separator+"upload"+File.separator;
File dir = new File(rootPath);
if (!dir.exists()){
dir.mkdirs();
}
for (MultipartFile file :fileArray){
if (null == file) break;
String originalFileName = file.getOriginalFilename();
String newFileName = DateUtil.currentDateTimeString2()+file.getOriginalFilename();
String finalPath = rootPath+newFileName;
if(!originalFileName.contains(".")) break;
String typ = originalFileName.substring(originalFileName.lastIndexOf("."));
if (typ.contains("avi") || typ.contains("AVI")){
content += " <object id=\"video\" width=\"400\" height=\"200\" border=\"0\" classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\">" +
" <param name=\"ShowDisplay\" value=\"0\">" +
" <param name=\"ShowControls\" value=\"1\">" +
" <param name=\"AutoStart\" value=\"1\">" +
" <param name=\"AutoRewind\" value=\"0\">" +
" <param name=\"PlayCount\" value=\"0\">" +
" <param name=\"Appearance value=\"0 value=\"\"\">" +
" <param name=\"BorderStyle value=\"0 value=\"\"\">" +
" <param name=\"MovieWindowHeight\" value=\"240\">" +
" <param name=\"MovieWindowWidth\" value=\"320\">" +
" <param name=\"FileName\" value=\""+accesspath+"/upload/"+newFileName+"\">" +
" <embed width=\"400\" height=\"200\" border=\"0\" showdisplay=\"0\" showcontrols=\"1\" autostart=\"1\" autorewind=\"0\" playcount=\"0\" "
+ " moviewindowheight=\"240\" moviewindowwidth=\"320\" "
+ " filename=\""+accesspath+"/upload/"+newFileName+"\" src=\""+accesspath+"/upload/"+newFileName+"\">"+
" </embed>"+
" </object>";
}else{
content += "<img src=\""+accesspath+"/upload/"+newFileName+"\" style=\"width:160px;height:180px\">";
}
File fileAttach = new File(finalPath);
fileAttach.createNewFile();
try {
file.transferTo(fileAttach);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
blog.setBlogname(content);
blog.setBlogtype(0);
blog.setFilepath("");
blog.setUsreid(userid);
blog.setSubmitdate(DateUtil.currentTime());
iSimpleDefaultService.save(blog);
System.out.println(content);
return "redirect:/user/index";
}
@RequestMapping(value="/comment", method=RequestMethod.POST)
public void addcomment(HttpServletRequest request,HttpServletResponse response, HttpSession session){
int userid = Integer.parseInt(session.getAttribute(DataHelpConstant.SESSION_USER.USER_ID).toString());
Result result = new Result();
String content = request.getParameter("content").trim();
int blogid = Integer.parseInt(request.getParameter("blogid").trim());
Comment comment = new Comment();
comment.setBlogid(blogid);
comment.setContent(content);
comment.setSubmituser(userid);
comment.setSubmitdate(DateUtil.currentTime());
iSimpleDefaultService.save(comment);
Userinfo userinfo = (Userinfo) iSimpleDefaultService.get(Userinfo.class, userid);
comment.setSubmitusername(userinfo.getDetail());
result.setCode(0);
result.setObj(comment);
result.setSuccess(true);
System.out.println(content);
this.writeJson(result, response);
}
@RequestMapping(value="/zan", method=RequestMethod.POST)
public void zan(HttpServletRequest request,HttpServletResponse response, HttpSession session){
int userid = Integer.parseInt(session.getAttribute(DataHelpConstant.SESSION_USER.USER_ID).toString());
Result result = new Result();
int blogid = Integer.parseInt(request.getParameter("blogid").trim());
String type = request.getParameter("operator");
if (type.equals("add")){
Zan zan = new Zan();
zan.setBlogid(blogid);
zan.setUser(userid);
iSimpleDefaultService.save(zan);
}else{
List list = iSimpleDefaultService.getObjectsByHql("from Zan where user="+userid+" and blogid = "+blogid);
if (null !=list && list.size()>0){
Zan zan = (Zan) list.get(0);
iSimpleDefaultService.remove(zan);
}
}
this.writeJson(result, response);
}
@RequestMapping(value="/zhuanfa", method=RequestMethod.POST)
public void zhuanfa(HttpServletRequest request,HttpServletResponse response, HttpSession session){
Result result = new Result();
result.setCode(0);
result.setSuccess(true);
int userid = Integer.parseInt(session.getAttribute(DataHelpConstant.SESSION_USER.USER_ID).toString());
int blogid = Integer.parseInt(request.getParameter("blogid"));
String content = request.getParameter("content");
Blog blog = (Blog) iSimpleDefaultService.get(Blog.class, blogid);
Blog newBlog = new Blog();
newBlog.setBlogname(content+"<hr>"+blog.getBlogname());
newBlog.setSubmitdate(DateUtil.currentTime());
newBlog.setUsreid(userid);
iSimpleDefaultService.save(newBlog);
this.writeJson(result, response);
}
@RequestMapping(value="/friends/userid/{userid}/type/{type}", method=RequestMethod.GET)
public String getFriends(@PathVariable("userid") int userid,@PathVariable("type") int type,
HttpServletRequest request,HttpServletResponse response, HttpSession session){
Result result = new Result();
result.setCode(0);
result.setSuccess(true);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于jsp的微博 (1788个子文件)
.classpath 1KB
org.eclipse.wst.common.component 752B
org.eclipse.wst.jsdt.ui.superType.container 49B
ext-theme-neptune-touch-all-rtl-debug_01.css 976KB
ext-theme-neptune-all-rtl-debug_01.css 976KB
ext-theme-neptune-all-debug_01.css 975KB
ext-theme-neptune-touch-all-debug_01.css 975KB
ext-theme-neptune-all_01.css 369KB
ext-theme-neptune-touch-all_01.css 369KB
ext-theme-neptune-touch-all-rtl_01.css 367KB
ext-theme-neptune-all-rtl_01.css 367KB
ext-ux-all-rtl-debug.css 178KB
ext-ux-all-debug.css 178KB
ext-ux-all-rtl-debug.css 178KB
ext-ux-all-debug.css 178KB
ext-ux-all-rtl-debug.css 178KB
ext-ux-all-debug.css 178KB
ext-theme-neptune-touch-all-rtl-debug_02.css 144KB
ext-theme-neptune-all-rtl-debug_02.css 144KB
bootstrap.css 134KB
bootstrap.min.css 98KB
ext-theme-neptune-touch-all-debug_02.css 93KB
ext-theme-neptune-all-debug_02.css 93KB
ext-theme-neptune-all-rtl_02.css 92KB
ext-theme-neptune-touch-all-rtl_02.css 92KB
ext-theme-neptune-all_02.css 61KB
ext-theme-neptune-touch-all_02.css 61KB
index4.css 41KB
index.css 41KB
register.css 27KB
common.css 19KB
style.css 15KB
clearbox.css 10KB
qqZone.css 6KB
login_register.css 6KB
styles.css 5KB
chat.css 4KB
ext-ux-all.css 3KB
ext-ux-all.css 3KB
ext-ux-all.css 3KB
ext-ux-all-rtl.css 3KB
ext-ux-all-rtl.css 3KB
ext-ux-all-rtl.css 3KB
css.css 3KB
style.css 3KB
ext-theme-neptune-touch-all-rtl-debug.css 112B
ext-theme-neptune-touch-all-debug.css 104B
ext-theme-neptune-all-rtl-debug.css 100B
ext-theme-neptune-touch-all-rtl.css 98B
ext-theme-neptune-all-debug.css 92B
ext-theme-neptune-touch-all.css 90B
ext-theme-neptune-all-rtl.css 86B
ext-theme-neptune-all.css 78B
Thumbs.db 114KB
Thumbs.db 50KB
glyphicons-halflings-regular.eot 20KB
top_logos_sprite.gif 10KB
loadingb.gif 10KB
2010610122226.gif 4KB
tx_logo.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading.gif 2KB
loading_01.gif 2KB
1CA6RWCDS.gif 2KB
liveNewsLeft.gif 1KB
videoNewsLeft.gif 1KB
zhenyu_0.gif 1KB
U6893P1DT20110905170320.gif 1016B
drop-yes.gif 1016B
drop-yes.gif 1016B
add.gif 1010B
drop-add.gif 1001B
drop-add.gif 1001B
drop-no.gif 949B
drop-no.gif 949B
more-style-addthis.gif 827B
hq_img_bg.gif 736B
btn-default-large-sides.gif 661B
btn-default-large-over-sides.gif 655B
btn-default-large-over-sides.gif 641B
btn-default-medium-sides.gif 638B
btn-default-medium-over-sides.gif 638B
i_body1_news_n3.gif 629B
btn-default-large-focus-sides.gif 623B
btn-default-large-focus-over-sides.gif 619B
btn-default-large-focus-over-sides.gif 609B
btn-default-large-focus-sides.gif 608B
btn-default-medium-focus-over-sides.gif 604B
btn-default-medium-focus-sides.gif 604B
login_img9.gif 558B
btn-default-large-pressed-sides.gif 555B
login_img8.gif 553B
btn-default-large-sides.gif 543B
btn-default-large-pressed-sides.gif 540B
btn-default-medium-pressed-sides.gif 534B
共 1788 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
独来独往mk
- 粉丝: 20
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功