- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在开发一个 spring mvc 应用程序,我想在我的 Controller 中处理多部分请求。在请求中我也传递了 MultiPartFile
,目前我正在使用 @RequestParam
来获取文件参数,方法看起来像,
@RequestMapping(method = RequestMethod.POST)
public def save(
@ModelAttribute @Valid Product product,
@RequestParam(value = "image", required = false) MultipartFile file) {
.....
}
以上代码在我的服务中运行良好,并且文件正在服务器端。现在我在某个地方看到,如果该文件需要使用 @RequestPart
注释而不是 @RequestParam
。将 @RequestParam
用于文件有什么问题吗?或者将来可能会导致任何类型的错误?
最佳答案
使用 @RequestParam
和 Multipart
文件没有问题。
@RequestParam annotation can also be used to associate the part of a "multipart/form-data" request with a method argument supporting the same method argument types. The main difference is that when the method argument is not a String, @RequestParam relies on type conversion via a registered Converter or PropertyEditor while @RequestPart relies on HttpMessageConverters taking into consideration the 'Content-Type' header of the request part. @RequestParam is likely to be used with name-value form fields while @RequestPart is likely to be used with parts containing more complex content (e.g. JSON, XML).
关于java - 将@RequestParam 用于多部分文件是正确的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38156646/
所以我目前正在使用 Spring 构建一个 Multipart-Fileupload。我想创建尽可能通用的 Controller ,以便为我自己的模块化 Controller 应用程序提供良好的开端。
@RequestParam参数丢失 改动过一版代码之后, 发现@RequestParam注解的参数经常丢失. 首先确认前端确实把参数传过来了,用curl直接请求接口, 发现有时候会出现参数丢失,
概述 在这个快速教程中,我们将探索 Spring 的 @RequestParam 注解。 简单地说,我们可以使用 @RequestParam 从请求中提取查询参数、表单参数甚至文件。我们将讨论如何使用
我的@Restcontroller 中有以下方法: @GetMapping public List getByParameterOrAll( @RequestParam(value =
大家好!我有一个关于在 @RestController 中使用 @RequestParam 的问题。我想知道如何从客户端获取@RequestParam。服务器代码(@RestController):
我正在阅读 documentation Spring MVC 中的 @RequestParam 注释。 名称和值属性有什么区别? 文档说: value : Alias for name(). name
我正在尝试在我的 javascript 中获取一个 Java 对象。我正在使用 ajax 请求来获取该对象。这是我的代码: @RequestMapping(path = "/sendSMS", met
这是我在 stackoverflow 上提出的第一个问题,所以请温柔点:) 现有 GET 端点可转换为 POST。它需要扩展以接受包含 JSON 编码数据的查询参数 filterKeys。这种方法不是
假设我在 Spring Boot Controller 中有一个 GET 端点,它接受一个对象作为 @RequestParam @GetMapping(value = "/foos") public
我刚刚发现,即使我省略了 @RequestParam organization 上的注释参数,Spring仍然能够绑定(bind)它。 @RequestMapping(value="", 方法 = R
我有我的 RequestParam,我需要验证它,但是 mu 自定义验证不适用,我的 Controller @RestController @Validated class ExchangeContr
我正在 Spring 中构建一个 API,我有一个简单的问题: 我想在对下面的这些参数执行一些逻辑之前检查它们是否包含值。 我是 Spring 新手 - 有没有办法将这些值“获取”到某种数据结构中,以
我正在使用 Spring MVC 框架做一个 REST 服务。 我有一个方法: @RequestMapping("/rest/{tableName}", method = RequestMethod.
我有一个 Get 端点,它接受一个查询字符串作为请求参数。端点的问题是请求参数字符串可以包含像 ?,/等导致问题的字符。有什么方法可以将包含 ?,/等的字符串映射到 rest Controller 中
有没有办法在不检查每个函数的情况下使用 spring 验证请求参数?例如, Controller 中的每个方法都会生成元素列表,并且每个方法都接受“from”和“to”参数,因此验证是: from >
SpringMvc 中@RequestParam注解使用 建议使用包装类型来代替基本数据类型 ?
@RequestParam 绑定List参数 今天遇到了一个问题 比较尴尬。我写了一个接口,参数用@RequestParam接收,是一个List<String>。用postman可以
目录 基于name和value属性的区别 RequestParam内部有4个参数 @RequestParam,参数是否必须传的问题
1、源码展示 ? 1
配置全局乱码过滤器 参数绑定注解@RequestParam 注解@RequestParam的参数使用说明 获得Restful风格的参数 自定义类型转换器 自定义转换器的开发步骤: 获得Servlet相
我是一名优秀的程序员,十分优秀!