携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第21天,点击查看活动详情
-
springboot中接受前端上传的文件过大
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceedException:The field files[] exceeds its maximun permitted size of 1048576 bytes.
解决方法:
方法一.在application.properties中配置:
spring.http.multipart.maxFileSize=10Mb
spring.http.multipart.maxRequestSize=10Mb
方法二.写一个Config类:
@Configuration
public class MultipartConfigElementConfig{
@Bean
public MultipartConfigElement multipartConfigElement(){
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.parse("10240KB"));
factory.setMaxRequestSize(DataSize.parse("102400KB"));
return factory.createMultipartConfig();
}
}
-
springboot前端传的参数MultipartFile如何转换为InputStream
InputStream inputStream = null;
File file = null;
file = File.createTempFile("temp", null);
sourceFile.transferTo(file); //sourceFile为传入的MultipartFile
inputStream = new FileInputStream(file);
file.deleteOnExit();
-
文件上传错误
The type org.apache.common.fileUploadFilItem cannot be resolved.It is indirectly referenced from required .class file
解决方法:在pom中添加如下依赖:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
-
滚动条设置
Form添加滚动条:
.类名{
width:80%;
overflow-y:scroll; //表示在纵轴上加滚动
height:80%; //表示纵向高度只展示页面的80%,其余内容用来滚动
}
<Table>标签给页面设置默认显示条数:
<Table
bordered
dataSource={this.state.data}
scroll={{x : 2000}}
columns={this.columns}
pagination={
{pageSize:15} //这里设置的是每页条数,还可以添加其他属性
}
/>
使用antd的upload组件上传文件之后把数据处理之后又返回到前端,如何获取response:
可以在浏览器console里面输入info回车,然后打印出的内容里点开可以看到response,所以在前端代码中就可以按照打印出的内容里的response的路径获取response。
-
springboot中使用@Value获取application.properties中的配置取值为Null
@Value("${spring.datasource.url}")
private String url;
获取值为NUll。
解决方法:不要使用new的方法去创建工具类(DBUtils)对象,而是使用@Autowired的方式交由springboot来管理,在工具类上加上@Component,定义的属性变量不要加static。
正确做法:
@Autowired
private DBUtils jdbc;
@Component
public class DBUtils{
@Value("${spring.datasource.url}")
private String url;
}