springmvc file upload and download summary

1: premise springmvc upload files
got to pay attention when using xml configuration springmvc upload files, add the following code to our srpingmvc.xml in
the configuration file parser object, requires id name must be multipartResolver

    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="52428800"/>
    </bean>

Which <property name="maxUploadSize" value="52428800"/>you can configure their own
this is to limit the size of files that we upload
more than adding code that we can use this component of the

2: About how to read resource files from the database
when we pass back to the front of the document have been received we read how they do
this in two ways, at present I have just used one of them
first is that I their used method
2.1 when we receive front-end file, we first save the file to the current directory specified items, and then save the file in the project relative path to the database directly when we need to call file change the path to read, I give the following method to get the path

    File.separator是一个分隔符,在不同系统中有不同的表现
    String 资源文件的绝对路径 = request.getServletContext().getRealPath(File.separator+dirName);
    String 资源文件的相对路径 = request.getContextPath()+File.separator+dirName+File.separator+filename;

2.2 I have not tried this method, is to our database files directly, when we want to call you can read text resources directly from the database written in binary way, but I personally think that this method will database query speed impact, so I used this method is not recommended

Published 20 original articles · won praise 7 · views 7112

Guess you like

Origin blog.csdn.net/qq_43049583/article/details/104357735