【问题标题】:How to set default value of array to empty with @RequestParam [duplicate]如何使用@RequestParam将数组的默认值设置为空[重复]
【发布时间】:2019-01-18 06:33:09
【问题描述】:

所以我有一个这样的控制器方法:

@RequestMapping(value = "/stuff, method = GET)
public StuffDTO getStuff(
        @RequestParam(value = "stuffIds") List<Integer> ids) {

我知道我可以提供这样的默认值:

@RequestParam(value = "1,2,3")

但是如何将默认值设置为空列表,而不是处理端点实现中的null 列表?

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    只需提供一个空字符串作为默认值,不需要像[] 之类的东西。

    @RequestMapping(value = "/stuff, method = GET)
    public StuffDTO getStuff(
            @RequestParam(value = "stuffIds", defaultValue = "") List<Integer> ids) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-26
      • 2019-05-08
      • 2018-08-29
      • 2017-02-06
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多