Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring之后的多部分/表单数据_Java_Spring_Post_Multipartform Data - Fatal编程技术网

Java Spring之后的多部分/表单数据

Java Spring之后的多部分/表单数据,java,spring,post,multipartform-data,Java,Spring,Post,Multipartform Data,所以,我是一个真正的java初学者。。我正在做大量的工作和研究的应用程序 事情是这样的。我需要发布一些关于多部分/表单数据的信息。。。我曾经用Json HashMap来做这件事。但是不知道该用哪个对象来代替。。。以下是我的actioncontroller帖子: HashMap<String, ContentDTO> cnt = new HashMap<String, ContentDTO>(); ContentDTO contentDTO = new C

所以,我是一个真正的java初学者。。我正在做大量的工作和研究的应用程序

事情是这样的。我需要发布一些关于多部分/表单数据的信息。。。我曾经用Json HashMap来做这件事。但是不知道该用哪个对象来代替。。。以下是我的actioncontroller帖子:

HashMap<String, ContentDTO> cnt = new HashMap<String, ContentDTO>();

        ContentDTO contentDTO = new ContentDTO();
        contentDTO.setExternal_id("CNT1");
        contentDTO.setTemplate_type_id(103);
        contentDTO.setChannel_id("CHN1");
        contentDTO.setTitle("Conteudo1");
        contentDTO.setText("Conteudo teste 1");
        RulesDTO rules = new RulesDTO();
        SimpleDateFormat publish_date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss-SSS");
        java.util.Date pdate = publish_date.parse("2012-12-28 11:18:00-030");
        java.sql.Timestamp pubdate = new java.sql.Timestamp(pdate.getTime());
        rules.setPublish_date(pubdate);
        SimpleDateFormat expiration_date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss-SSS");
        java.util.Date edate = expiration_date.parse("2013-12-28 11:18:00-030");
        java.sql.Timestamp expdate = new java.sql.Timestamp(edate.getTime());
        rules.setExpiration_date(expdate);
        rules.setNotify_publish(true);
        rules.setNotify_expiration(false);
        rules.setHighlihted(true);

        contentDTO.setRules(rules);

        InteractionsDTO interactions = new InteractionsDTO();
        interactions.setAllow_comment(true);
        interactions.setAuto_download(false);

        contentDTO.setInteractions(interactions);


        cnt.put("content",contentDTO);




        HttpEntity<HashMap<String, ContentDTO>> request = new HttpEntity<HashMap<String, ContentDTO>>(cnt, httpHeaders);
HashMap cnt=newhashmap();
ContentDTO ContentDTO=新ContentDTO();
contentDTO.setExternal_id(“CNT1”);
contentDTO.setTemplate\u type\u id(103);
contentDTO.setChannel_id(“CHN1”);
contentDTO.setTitle(“Conteudo1”);
contentDTO.setText(“Conteudo teste 1”);
RulesDTO rules=新的RulesDTO();
SimpleDataFormat发布日期=新SimpleDataFormat(“yyyy-MM-dd hh:MM:ss SSS”);
java.util.Date pdate=publish_Date.parse(“2012-12-28 11:18:00-030”);
java.sql.Timestamp pubdate=new java.sql.Timestamp(pdate.getTime());
规则。设置发布日期(pubdate);
SimpleDataFormat到期日=新SimpleDataFormat(“yyyy-MM-dd hh:MM:ss SSS”);
java.util.Date-edate=expiration_Date.parse(“2013-12-28 11:18:00-030”);
java.sql.Timestamp expdate=new java.sql.Timestamp(edate.getTime());
规则。设置到期日(expdate);
规则。setNotify_publish(true);
规则。setNotify_到期(false);
规则。setHighlihted(true);
contentDTO.setRules(规则);
InteractionsDTO interactions=新的InteractionsDTO();
交互。setAllow_注释(true);
交互。setAuto_下载(错误);
contentDTO.setInteractions(交互);
cnt.put(“内容”,contentDTO);
HttpEntity请求=新的HttpEntity(cnt、HttpHeader);

有人能帮我吗???

因为你需要使用multipart上传,我认为你必须使用File对象,特别是来自Spring的

使用Spring您必须使用Spring控制器在UI层中工作,无需管理HttpEntity。只需在配置文件中声明多部分解析器

<beans>
<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
<!-- Declare explicitly, or use <context:annotation-config/> -->
<bean id="fileUploadController" class="examples.FileUploadController"/>

</beans>

这是从中提取的。你可以查一些例子。在这里,我将给你更多:


最后,我建议您使用MVC模式。不要在UI层中创建DTO并使用它的访问器,而要在业务层中创建服务或门面来实现这一点。

Hi,首先我建议您查看[spring文档][1]。通常,多部分用于文件上载。你是否需要上传一个文件作为使用multipart的练习的一部分,或者它只是一个发送散列图的普通请求?[1] :实际上,我将使用其他应用程序api发布它。。但它要求我使用multipart…有可能知道您使用的其他API是什么?与ApacheCommons多部分库一样,您发布的代码与此无关。更重要的是控制器的签名。最重要的是你使用的是什么版本的Spring。根据您的帖子,您似乎正在使用旧版本,或者至少没有使用注释驱动的控制器。答案因版本而异。谢谢jmva!!对我来说很好!