【发布时间】:2013-01-10 13:02:34
【问题描述】:
所以,我是一个真正的 Java 初学者.. 我正在做一个应用程序,需要大量的工作和研究......
事情是这样的。我需要用 multipart/form-data 发布一些信息……我以前用 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);
谁能帮帮我?
【问题讨论】:
-
您好,首先我建议您查看 [spring 文档][1]。通常 multipart 用于文件上传。您是否需要上传文件作为使用 multipart 的练习的一部分,或者它可能只是发送该哈希映射的正常请求? [1]:static.springsource.org/spring/docs/3.0.0.M3/reference/html/…
-
实际上,我会使用其他应用程序 api 发布它。但它要求我使用 multipart...
-
有可能知道您还使用了哪些其他 API?如 Apache Commons 多部分库等
-
您发布的代码无关紧要。更重要的是您的控制器的签名。最重要的是您使用的是什么版本的 Spring。根据您的帖子,您似乎使用的是旧版本,或者至少没有使用注释驱动的控制器。答案会因版本而异。
标签: java spring post multipartform-data