📄 bgnewupaction.java
字号:
package com.model.action;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;
import org.hibernate.Hibernate;
import com.model.entity.Accessories;
import com.model.entity.NewsInfo;
import com.model.entity.UserInfo;
import com.model.form.BginsertForm;
import com.model.logic.BackLogic;
import com.project.util.DateTimeUtil;
import com.project.util.StringUtil;
import com.project.util.UploadFile;
import com.project.util.UploadUitl;
public class BgNewUpAction extends DispatchAction {
public UploadUitl upload;
public BackLogic backLogic;
public BackLogic getBackLogic() {
return backLogic;
}
public void setBackLogic(BackLogic backLogic) {
this.backLogic = backLogic;
}
public UploadUitl getUpload() {
return upload;
}
public void setUpload(UploadUitl upload) {
this.upload = upload;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BginsertForm attachForm = (BginsertForm) form;
List attachFiles = new ArrayList();
for (int i = 0; i < 1; i++) {
attachFiles.add(new UploadFile());
}
attachForm.setAttachFiles(attachFiles);
return mapping.findForward("add");
}
/**
* 多文件上传
*/
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BginsertForm attachForm = (BginsertForm) form;
List attachFiles = attachForm.getAttachFiles();
HttpSession session = request.getSession(true);
UserInfo user = (UserInfo) session.getAttribute("userInfo");
Set set = new HashSet();
String fileFalgName = "";
if (user != null) {
NewsInfo newsInfo = new NewsInfo();
if ("地方动态".equals(attachForm.getKind())
|| "地方动态".equals(attachForm.getSort())) {
newsInfo.setNewsRole("0");
} else {
newsInfo.setNewsRole(attachForm.getNewrole());
}
newsInfo.setKind(attachForm.getKind());
newsInfo.setSort(attachForm.getSort());
newsInfo.setCreateDate(attachForm.getCreateDate());
newsInfo.setNewsDate(attachForm.getNewsDate());
newsInfo.setNewsKey(attachForm.getNewsKey());
newsInfo.setAuthor(attachForm.getAuthor());
String content = attachForm.getContent();
if (content.length() > 1000 && content.length() < 2000) {
content += StringUtil.aa;
}
newsInfo.setContent(Hibernate.createClob(attachForm.getContent()));
newsInfo.setTitle(attachForm.getTitle());
newsInfo.setNewsId(attachForm.getNewsId());
newsInfo.setNewsTop(attachForm.getNewsTop());
for (int i = 0; i < attachFiles.size(); i++) {
Accessories acc = new Accessories();
UploadFile attachFile = (UploadFile) attachFiles.get(i);
FormFile file = attachFile.getFile();
if (file != null) {
InputStream in = file.getInputStream();
String filePath = this.getUpload().getPath();
fileFalgName = DateTimeUtil.getDateFlag(file.getFileName());
acc.setAccessoriesName(file.getFileName());
acc.setAccessoriesDate(DateTimeUtil.getNowDate());
acc.setAccessoriesNameDate(fileFalgName);
OutputStream out = new FileOutputStream(filePath + "\\"
+ fileFalgName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
set.add(acc);
out.close();
in.close();
}
}
newsInfo.setAccessoriess(set);
this.getBackLogic().bgnewup(newsInfo);
attachForm.setAttachFiles(null);
return mapping.findForward("ok");
} else {
request.setAttribute("exit", "yes");
return mapping.findForward("no");
}
}
/**
* 归类
*/
public ActionForward rank(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BginsertForm attachForm = (BginsertForm) form;
HttpSession session = request.getSession();
UserInfo user = (UserInfo) session.getAttribute("userInfo");
String newsId = "";
if (user == null) {
request.setAttribute("exit", "yes");
return mapping.findForward("no");
} else {
newsId = (String) request.getParameter("newsId");
boolean temp = this.getBackLogic().updateNewsInfo(newsId,
attachForm.getKind(), attachForm.getSort());
return mapping.findForward("ok");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -