上传文件时同时提交参数

接口风格:restful
框架:resteasy
问题:上传文件时,需要提交其他的参数信息.
解决方案:在接口参数中使用pojo类来接受参数,

此接口入参为:multipart/form-data类型,
接口参数中的的pojo类,使用@MultipartForm来标注,
此pojo类中,封装好接口中所需要的所有参数.包含二进制文件.
源代码如下:
controller层代码:

@POST
@Path(value = "audit")
@Consumes("multipart/form-data")
public Response codeAudit(@MultipartForm ApiProject diskFile,
@Context HttpServletRequest request) {
System.out.println(diskFile);
        return Response.status(200).entity(JSONObject.quote("上传文件名: ")).build();
}



pojo类:


public class ApiProject {
    String fileName;
    String projectKey;
    String projectVersion;
    String projectLanguage;
    String projectEncoding;
    String projectSources;
    String projectClassPath;
    String jobKey;
    private byte[] fileDate;

    public String getFileName() {
        return fileName;
    }

    @FormParam("fileName")
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public byte[] getFileDate() {
        return fileDate;
    }

    @FormParam("file_upload")//此处名字,应与前台上传的文件name相等.
    @PartType(MediaType.APPLICATION_OCTET_STREAM)//上传类型.
    public void setFileDate(byte[] fileDate) {
        this.fileDate = fileDate;
    }

    public String getProjectKey() {
        return projectKey;
    }

    @FormParam("projectKey")
    public void setProjectKey(String projectKey) {
        this.projectKey = projectKey;
    }

    public String getProjectVersion() {
        return projectVersion;
    }

    @FormParam("projectVersion")
    public void setProjectVersion(String projectVersion) {
        this.projectVersion = projectVersion;
    }

    public String getProjectLanguage() {
        return projectLanguage;
    }

    @FormParam("projectLanguage")
    public void setProjectLanguage(String projectLanguage) {
        this.projectLanguage = projectLanguage;
    }

    public String getProjectEncoding() {
        return projectEncoding;
    }

    @FormParam("projectEncoding")
    public void setProjectEncoding(String projectEncoding) {
        this.projectEncoding = projectEncoding;
    }

    public String getProjectSources() {
        return projectSources;
    }

    @FormParam("projectSources")
    public void setProjectSources(String projectSources) {
        this.projectSources = projectSources;
    }

    public String getProjectClassPath() {
        return projectClassPath;
    }

    @FormParam("projectClassPath")
       public void setProjectClassPath(String projectClassPath) {
        this.projectClassPath = projectClassPath;
    }

    public String getJobKey() {
        return jobKey;
    }
    
    @FormParam("jobKey")
    public void setJobKey(String jobKey) {
        this.jobKey = jobKey;
    }

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值