Created
October 7, 2014 01:41
-
-
Save A-pZ/577d1f0b3aa0118ec523 to your computer and use it in GitHub Desktop.
複数ファイルアップロード対応のActionクラス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
package lumi.action.upload; | |
import java.io.File; | |
import java.util.HashMap; | |
import java.util.Map; | |
import lombok.Getter; | |
import lombok.Setter; | |
import lombok.extern.slf4j.Slf4j; | |
import lumi.action.LumiActionSupport; | |
import org.apache.commons.io.FileUtils; | |
import org.apache.struts2.convention.annotation.Action; | |
import org.apache.struts2.convention.annotation.Namespace; | |
import org.apache.struts2.convention.annotation.ParentPackage; | |
import org.apache.struts2.convention.annotation.Result; | |
import org.apache.struts2.convention.annotation.Results; | |
import org.springframework.context.annotation.Scope; | |
import org.springframework.stereotype.Controller; | |
import com.opensymphony.xwork2.ActionSupport; | |
/** | |
* @author A-pZ | |
* | |
*/ | |
@Namespace("/upload") | |
@ParentPackage("lumi-default") | |
@Results({ | |
@Result(name = ActionSupport.SUCCESS, type = "json" , params={"root","result"}), | |
}) | |
@Controller | |
@Scope("prototype") | |
@Slf4j | |
public class UploadAction extends LumiActionSupport { | |
@Action("upload") | |
public String upload() throws Exception { | |
for (int i=0;i<picture.length;i++ ) { | |
// 中間ファイルをコピー | |
File uploadFile = new File( UPLOAD_DIR + "/" + pictureFileName[i]); | |
FileUtils.copyFile(picture[i], uploadFile); | |
log.info( " upload [" + uploadFile.getAbsolutePath() + "] complete." ); | |
} | |
result = new HashMap<String,Object>(); | |
result.put("result", "success"); | |
result.put("message", getText("upload.complete")); | |
return ActionSupport.SUCCESS; | |
} | |
private static final String UPLOAD_DIR = "E:/deploy"; | |
@Getter | |
@Setter | |
private File[] picture; | |
@Getter | |
@Setter | |
private String[] pictureContentType; | |
@Getter | |
@Setter | |
private String[] pictureFileName; | |
@Getter | |
private Map<String,Object> result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment