package com.qm.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import com.qm.entity.Album;
import com.qm.service.IAlbumService;
/**
 * 相册控制层
 * @author quanmin
 *
 */
public class AlbumAction extends ActionSupport implements SessionAware {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Album album;
	private IAlbumService albumService;
	private Map<String, Object> sessionMap;
	private File file;
	private String fileFileName;
	//提交过来的file的MIME类型
    private String fileContentType;
	/**
	 * 添加
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception{
		String root=ServletActionContext.getServletContext().getRealPath("/album");
	    InputStream is=new FileInputStream(file);
	    OutputStream os = new FileOutputStream(new File(root, fileFileName));
	    byte[] buffer=new byte[500];
	    @SuppressWarnings("unused")
		int length=0;
	    while(-1 !=(length=is.read(buffer,0,buffer.length))){
	       os.write(buffer);
	    }
	    os.close();
	    is.close();
	    Album al=new Album("album/"+fileFileName);
		albumService.add(al);
		return "add";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception{
		albumService.delete(album.getAlbumId());
		return "delete";
	}
	/**
	 * 通过id查询
	 * @return
	 * @throws Exception
	 */
	public String findById() throws Exception{
		this.album=albumService.findByid(album.getAlbumId());
		return "findById";
	}
	/**
	 * 查找所有
	 * @return
	 * @throws Exception
	 */
	public String findAll() throws Exception{
		List<Album> albumList=albumService.findAll();
		sessionMap.put("albumList", albumList);
		return "findAll";
	}
	public Album getAlbum() {
		return album;
	}
	public void setAlbum(Album album) {
		this.album = album;
	}
	public void setAlbumService(IAlbumService albumService) {
		this.albumService = albumService;
	}
	public void setSession(Map<String, Object> sessionMap) {
		this.sessionMap=sessionMap;
	}
	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;
	}
	
}
最近下载更多
                
                wanglinddad     LV55
                2022年3月18日
            
            
        
                adim10912     LV2
                2022年3月5日
            
            
        
                and123456     LV11
                2022年2月7日
            
            
        
                977903096     LV10
                2021年12月23日
            
            
        
                15966848095     LV22
                2021年11月15日
            
            
        
                SOLEIL.     LV3
                2021年6月19日
            
            
        
                15525425383     LV6
                2021年5月23日
            
            
        
                rongfan     LV14
                2021年4月6日
            
            
        
                yyy777     LV5
                2021年2月4日
            
            
        
                ExamplesDYC     LV13
                2020年11月21日
            
            
        
最近浏览更多
                
                vincemokea     LV9
                9月14日
            
            
        
                Peny_ZH     LV5
                2024年9月21日
            
            
        
                educationAAA     LV11
                2024年5月8日
            
            
        
                WBelong     LV8
                2023年12月11日
            
            
        
                拜托你仔细听     LV3
                2023年9月21日
            
            
        
                zj20020510     LV5
                2023年9月18日
            
            
        
                周敏国     LV9
                2023年8月21日
            
            
        
                xuxin2000    
                2023年8月17日
            
            
                    暂无贡献等级
            
        
                枫眠啊啊啊啊啊啊啊啊    
                2023年7月28日
            
            
                    暂无贡献等级
            
        
                刘洋66666     LV1
                2023年7月14日
            
            
        
                
                
                