easyui多文件上传到指定路径

效果图如下

easyui多文件上传到指定路径_第1张图片

在网上查找一番后,参考别人的代码,记录下来,方便以后查阅

引入的js包

jquery.easyui.min.js

jquery.min.js

ssm框架实现后台

多文件上传的核心是input标签中设置multiple="true"

设置这个之后通过手按ctrl可以选择多个文件进行上传

(一)bady中添加


	

(二)js代码

 

(三)后天代码

@Controller
@RequestMapping("/order")
public class OrderController {
	/**
	 * 上传文件
	 * @param file
	 * @return
	 */
	@RequestMapping("/upload")
	@ResponseBody
	public OperationResultMsg springUpload(@RequestParam(value = "file", required = false)CommonsMultipartFile[]  files,HttpServletRequest request)
	    {
	        //上传文件保存位置
	        String pathString =  request.getSession().getServletContext().getRealPath("/upload");
	        //判断文件夹是否存在
	        File file=new File(pathString);
	        if(!file.isDirectory())
	        {
	            //创建文件夹
	            file.mkdirs();
	        }
	        //批量上传
	        for(int i = 0;i
/**
 * 操作结果通知信息        实体类             
 */
public class OperationResultMsg implements Serializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -3349098656492188022L;
    private int id;
    private String resultMsg;
    private Object extraMsg;

    public OperationResultMsg(OperationResultCode code)
    {
        this.id = code.getId();
        this.resultMsg = code.getMsg();
    }

    public OperationResultMsg(OperationResultCode code, Object extraMsg)
    {
        this.id = code.getId();
        this.resultMsg = code.getMsg();
        this.extraMsg = extraMsg;
    }
    public OperationResultMsg()
    {
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public Object getExtraMsg()
    {
        return extraMsg;
    }

    public void setExtraMsg(Object extraMsg)
    {
        this.extraMsg = extraMsg;
    }

    public String getResultMsg()
    {
        return resultMsg;
    }
    public void setResultMsg(String resultMsg)
    {
        this.resultMsg = resultMsg;
    }
    
    
    /**
     * 账号操作结果代码
     */
    public enum OperationResultCode
    {
        SUCCESS(0, "操作成功"),
        UPLOADING_FILE(1, "上传文件成功!"),
        UPLOADING_FILE_OPTION(2, "请选择上传文件"),
        ;

        private int id;
        private String msg;

        private OperationResultCode(int id, String msg)
        {
            this.id = id;
            this.msg = msg;
        }

        public int getId()
        {
            return id;
        }

        public void setId(int id)
        {
            this.id = id;
        }

        public String getMsg()
        {
            return msg;
        }

        public void setMsg(String msg)
        {
            this.msg = msg;
        }
    }
}

 

你可能感兴趣的:(easyui多文件上传到指定路径)