首页>代码>基于ssh框架开发ktv预定管理系统(加毕业论文)>/1069基于ssh-ktv预定管理系统 - 副本/code/ktvManage/src/com/my/pro/action/GqAction.java
package com.my.pro.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
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.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.my.pro.utils.Pager;
import com.my.pro.utils.UUIDUtils;
import com.opensymphony.xwork2.ModelDriven;
import java.util.*;

import com.my.pro.model.*;
import com.my.pro.dao.*;
import com.my.pro.service.*;

/**
 * @ClassName:  
 * @Description: 
 * @author administrator
 * 
 */

@Controller("gqAction")
@Scope("prototype")
public class GqAction extends BaseAction implements ModelDriven<Gq>{
	
	private static final long serialVersionUID = 1L;


	
	//==========model==============
	  private Gq gq;
		@Override
		public Gq getModel() {
			if(gq==null) gq = new Gq();
			return gq;	
		}
		//==========model==============
	/**
	 * 依赖注入 start dao/service/===
	 */
	@Autowired
	private GqService gqService;
	
	//依赖注入 end  dao/service/===
	
	//-------------------------华丽分割线---------------------------------------------
	
	//============自定义参数start=============
	
	//============自定义参数end=============

	
	//-------------------------华丽分割线---------------------------------------------
	
	//============文件上传start=======================================================
	
	
	private File file;
	//提交过来的file的名字
    private String fileFileName;
    //提交过来的file的MIME类型
    private String fileContentType;
    public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
	 //============文件上传end=========================================================
	public String jsonAction() {
		  // dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
		  jsonMap.clear();
		  jsonMap.put("success", true);
		  return JSON_TYPE;
	}
	 //-------------------------华丽分割线---------------------------------------------//
	
	 //=============公=======共=======方=======法==========区=========start============//
	/**
	 * 列表分页查询 and isDelete = 0 
	 * 
	 */
	public String gq(){
	    Map<String,Object> alias = new HashMap<String,Object>();
		StringBuffer sb = new StringBuffer();
		sb = sb.append("from Gq where 1=1 and isDelete =0 ");
		if(gq!=null && gq.getName() !=null && !"".equals(gq.getName())){
			sb.append("  and name like :realName ");
			alias.put("realName", "%" +gq.getName()+ "%" );
		}
		sb = sb.append("order by id desc");
		Pager<Gq> pagers = gqService.findByAlias(sb.toString(),alias);
		ActionContext.getContext().put("pagers", pagers);
		ActionContext.getContext().put("Obj", gq);
		return SUCCESS;
    }
	
	/**
	 * 跳转到添加页面
	 * @return
	 */
	public String add(){
		return SUCCESS;
	}
	
	/**
	 * 执行添加
	 * @return
	 * @throws IOException 
	 */
	public String exAdd() throws IOException{
		String root  = "D:/my/upload";
		 InputStream is = new FileInputStream(file);
	        fileFileName = UUIDUtils.create()+fileFileName;
	        OutputStream os = new FileOutputStream(new File(root, fileFileName));
	        System.out.println("fileFileName: " + fileFileName);
	        System.out.println("file: " + file.getName());
	        System.out.println("file: " + file.getPath());
	        byte[] buffer = new byte[500];
	        int length = 0; 
	        
	        while(-1 != (length = is.read(buffer, 0, buffer.length)))
	        {
	            os.write(buffer);
	        }
	        os.close();
	        is.close();
	        gq.setUrls("\\upload\\"+fileFileName);
	        gq.setNum(0);
	        gq.setIsDelete(0);
		gqService.save(gq);
		ActionContext.getContext().put("url", "/gq_gq.do");
		return "redirect";
	}
	
	/**
	 * 查看详情页面
	 * @return
	 */
	public String view(){
		Gq n = gqService.getById(gq.getId());
		ActionContext.getContext().put("Obj", n);
		return SUCCESS;
	}
	
	/**
	 * 跳转修改页面
	 * @return
	 */
	public String update(){
		Gq n = gqService.getById(gq.getId());
		ActionContext.getContext().put("Obj", n);
		return SUCCESS;
	}
    
	/**
	 * 执行修改
	 * @return
	 * @throws IOException 
	 */
	public String exUpdate() throws IOException{
		Gq n = gqService.getById(gq.getId());
		String root  = "D:/my/upload";
		 InputStream is = new FileInputStream(file);
	        fileFileName = UUIDUtils.create()+fileFileName;
	        OutputStream os = new FileOutputStream(new File(root, fileFileName));
	        System.out.println("fileFileName: " + fileFileName);
	        System.out.println("file: " + file.getName());
	        System.out.println("file: " + file.getPath());
	        byte[] buffer = new byte[500];
	        int length = 0; 
	        
	        while(-1 != (length = is.read(buffer, 0, buffer.length)))
	        {
	            os.write(buffer);
	        }
	        os.close();
	        is.close();
	        n.setUrls("\\upload\\"+fileFileName);
	        BeanUtils.copyProperties(gq, n, getNullPropertyNames(gq));
		gqService.update(n);
		ActionContext.getContext().put("url", "/gq_gq.do");
		return "redirect";
	}
	
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		//gqService.delete(gq.getId());
		Gq n = gqService.getById(gq.getId());
		n.setIsDelete(1);
		gqService.update(n);
		ActionContext.getContext().put("url", "/gq_gq.do");
		return "redirect";
	}
	
	//=============公=======共=======方=======法==========区=========end============//
	
	 //-------------------------华丽分割线---------------------------------------------//
	
	 //=============自=======定=======义=========方=======法==========区=========start============//
	
	
	
	
	//=============自=======定=======义=========方=======法==========区=========end============//
		
	
	
}
最近下载更多
pannifeng  LV2 2022年11月21日
五折也挺好的  LV13 2022年10月23日
yang future  LV4 2022年10月14日
591231555  LV20 2022年4月18日
MyPary  LV6 2022年4月3日
qlpqlp  LV7 2022年3月13日
karthurly  LV3 2022年3月8日
muzijijian  LV5 2022年2月17日
1983448992  LV8 2022年1月26日
北巷枫  LV9 2022年1月15日
最近浏览更多
wenpeng182013  LV7 2024年12月14日
shunlun8855  LV1 2024年10月29日
chutianyu  LV4 2024年9月29日
诗洛荨  LV3 2024年8月10日
cyd yyds  LV2 2024年8月5日
quye12 2024年6月20日
暂无贡献等级
hfffff  LV1 2024年6月3日
玖零定制问题修复  LV34 2024年4月4日
GJQ123  LV4 2024年4月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友