所以,我是一个真正的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);有人能帮我吗??
发布于 2013-01-10 22:22:10
因为你需要使用多部分上传,所以我认为你必须使用一个文件对象,特别是来自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>这是从official Spring 3 Documentation中提取的。你可以看看这里的一些例子。这里我将给你更多:Spring 3 File Upload Example,Spring MVC file upload。
最后,我建议您使用MVC模式。不要在UI层中创建DTO并使用它的访问器,而是在业务层中创建一个Service或Facade来实现这一点。
https://stackoverflow.com/questions/14258564
复制相似问题