【问题标题】:Trying to make a request with or without parameters尝试使用或不使用参数发出请求
【发布时间】:2020-11-06 13:27:06
【问题描述】:

我正在尝试根据以下代码发出带或不带参数的请求:

@RequestMapping(value = "/threshold/list", method = RequestMethod.GET)
public List<Threshold> listThreshold(@RequestParam(required = false) String categoria, @RequestParam(required = false) String kpi, @RequestParam(required = false) String data, @RequestParam(required = false) String hora) {
    
    return thresholdQuery.listThreshold(categoria, kpi, data, hora);
}

但是当我这样调用端点时:

http://localhost:8081/threshold/list?categoria=casa

我收到以下错误:

Not enough variable values available to expand 'categoria=casa'

【问题讨论】:

  • @RequestParam(required = false) 更改为@RequestParam(value="categoria",required = false) 是否有效(与kpidatahora 相同)?
  • 如何调用端点?
  • 你是直接从浏览器调用它..还是你正在使用RestTemplate?如果您使用的是 RestTemplate,请分享调用此 api 的代码
  • dan1st 我做了你的更改,但仍然出现同样的错误。

标签: java spring-boot rest


【解决方案1】:

我认为应该是“名称”而不是“价值”

@RequestParam(name="categoria",required = false)

【讨论】:

    猜你喜欢
    • 2020-05-08
    • 2014-04-15
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    相关资源
    最近更新 更多