IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

二十、文件上传

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

关于文件上传的支持,很多朋友询问为何Ui界面不显示上传选择页面元素,而是输入框,这里做一个统一的说明

SwaggerBootstrapUi以前的版本中(1.8.9之前),如果需要使用文件上传,界面显示,需要做如下代码设置:

@ApiOperation(value = "多文件MultipartFile上传")
@ApiImplicitParams({@ApiImplicitParam(name = "file[]", value = "文件流对象,接收数组格式", required = true,dataType = "MultipartFile",allowMultiple = true),
                    @ApiImplicitParam(name = "title", value = "title", required = true)}
                  )
@RequestMapping(value="/uploadMaterial",method = RequestMethod.POST)
@ResponseBody
public RestMessage uploadMaterial(@RequestParam(value="file[]",required = true) MultipartFile[] files,@RequestParam(value = "title") String title, HttpServletRequest request) throws IOException {
    //int mul=1*1024*1024;
    List<Map> uploadFiles= upload(request,files);
    RestMessage rm=new RestMessage();
    rm.setData(uploadFiles);
    return rm;
}

需要指定dataType="MultipartFile",并且allowMultiple = true必须设置,该属性从字面意思能知道,允许多文件上传,这里需要说明一下,因为在以前的版本作者并不知道文件的类型,所以特意强加了MultipartFile类型,来达到Ui的线上显示效果,所以单文件的上传一直并未支持.

1.9.0版本中,添加了对单文件上传的支持,多文件上传不需要多个input元素,开发者只需要按住Ctrl键即可多选文件进行上传,三种情况供大家参考使用:

多文件MultipartFile类型上传

这种类型在以前的版本中都支持,需要指定dataType="MultipartFile",并且allowMultiple = true,示例代码如下:

@ApiOperation(value = "多文件MultipartFile上传")
@ApiImplicitParams({@ApiImplicitParam(name = "file[]", value = "文件流对象,接收数组格式", required = true,dataType = "MultipartFile",allowMultiple = true),
                    @ApiImplicitParam(name = "title", value = "title", required = true)}
                  )
@RequestMapping(value="/uploadMaterial",method = RequestMethod.POST)
@ResponseBody
public RestMessage uploadMaterial(@RequestParam(value="file[]",required = true) MultipartFile[] files,@RequestParam(value = "title") String title, HttpServletRequest request) throws IOException {
    //more.....

}

在Ui的界面中,显示效果如下:

80_1.png

80_2.png

多文件File类型上传

除了dataType类型设置为MultipartFile外,开发者还可以设置为__File类型,代码示例如下:

@ApiOperation(value = "多文件File上传")
@ApiImplicitParams({@ApiImplicitParam(name = "file[]", value = "文件流对象,接收数组格式", required = true,dataType = "__File",allowMultiple = true),
                    @ApiImplicitParam(name = "title", value = "title", required = true)}
                  )
@RequestMapping(value="/uploadMaterial1",method = RequestMethod.POST)
@ResponseBody
public RestMessage uploadMaterial1(@RequestParam(value="file[]",required = true) MultipartFile[] files,@RequestParam(value = "title") String title, HttpServletRequest request) throws IOException {
    //more....
}

80_3.png

80_4.png

单文件File类型上传

和多文件File类型上传类似,只需要去掉allowMultiple = true属性即可,代码示例如下:

@ApiOperation(value = "单文件File上传")
@ApiImplicitParams({@ApiImplicitParam(name = "file", value = "文件流对象,接收数组格式", required = true,dataType = "__File"),
                    @ApiImplicitParam(name = "title", value = "title", required = true)}
                  )
@RequestMapping(value="/uploadMaterial2",method = RequestMethod.POST)
@ResponseBody
public RestMessage uploadMaterial2(@RequestParam(value="file",required = true) MultipartFile file,@RequestParam(value = "title") String title, HttpServletRequest request) throws IOException {
    //more...
}

80_5.png

80_6.png

以上三种情况示例可参考demo代码UploadController.java

干货推荐

文章永久链接:https://tech.souyunku.com/?p=11143


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(92) 打赏



未经允许不得转载:搜云库技术团队 » 二十、文件上传

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367