Package org.jiaplee.action

Source Code of org.jiaplee.action.ImageAction

package org.jiaplee.action;

import java.io.File;
import java.io.IOException;


import org.apache.commons.io.FileUtils;
import org.jiaplee.beans.Image;
import org.jiaplee.service.ImageService;

import com.opensymphony.xwork2.ActionSupport;
/**
*
*  图书上传请求action
*/
public class ImageAction extends ActionSupport {
  /**
   *
   */
  private static final long serialVersionUID = 3777511883889840780L;
  private String contentType;
  //图片类型
  private File upload;
  //文件
  private String fileName;
  //文件名
  private String caption;
  //文件说明
  // 服务 类  spring 自动注入
  private ImageService imageService;
 
  private java.io.Serializable serializable;

  public java.io.Serializable getSerializable() {
    return serializable;
  }

  public void setSerializable(java.io.Serializable serializable) {
    this.serializable = serializable;
  }
 
  public void setImageService(ImageService imageService) {
    this.imageService = imageService;
  }

  public String getUploadFileName() {
    return fileName;
  }

  public void setUploadFileName(String fileName) {
    this.fileName = fileName;
  }

  public String getUploadContentType() {
    return contentType;
  }

  public void setUploadContentType(String contentType) {
    this.contentType = contentType;
  }

  public File getUpload() {
    return upload;
  }

  public void setUpload(File upload) {
    this.upload = upload;
  }

  public String getCaption() {
    return caption;
  }

  public void setCaption(String caption) {
    this.caption = caption;
  }


  @Override
  public String execute() {
    System.out.println(this.fileName);
    System.out.println(this.contentType);
    System.out.println(this.caption);
    System.out.println(imageService);
    //实例化
    Image i = new Image();
    i.setId(fileName.hashCode());
    i.setFileName(fileName);
    i.setCaption(caption);
    try {
      i.setImage(FileUtils.readFileToByteArray(upload));
    } catch (IOException e) {
      e.printStackTrace();
    }
    // 保存数据
    this.serializable = imageService.save(i);
    return SUCCESS;
  }

}
TOP

Related Classes of org.jiaplee.action.ImageAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.