我有个2 javabean
public class ObjectA {
private long id;
private byte[] data;
private MultipartFile file;
}
public class ObjectB {
private String name;
private List<ObjectA> objectA ;
}
public Result Modify(ObjectB b)throws Exception
现在的问题是,file=null 时回保存。
如何允许file为空
contoller层方法参数中接收
@RequestParam(value = "file") CommonsMultipartFile file
页面form中写入 enctype="multipart/form-data"
<!--文件上传spring配置-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--文件限定为8M-->
<property name="maxUploadSize" value="8388608"></property>
</bean>
引包,我这是maven。其他架构,你可以自己下jar
<!--文件上传-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!--文件上传-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
@RequestParam(value = "file") CommonsMultipartFile file
页面form中写入 enctype="multipart/form-data"
<!--文件上传spring配置-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--文件限定为8M-->
<property name="maxUploadSize" value="8388608"></property>
</bean>
引包,我这是maven。其他架构,你可以自己下jar
<!--文件上传-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!--文件上传-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2017-07-25
Spring注解?