[英]RequestParam.defaultValue value
I am getting: 我正进入(状态:
The value for annotation attribute RequestParam.defaultValue must be a constant expression
but I have declared MAX_LONG_AS_STRING as a constant (static final): 但我已将MAX_LONG_AS_STRING声明为常量(静态最终):
private static final String MAX_LONG_AS_STRING = Long.toString(Long.MAX_VALUE);
@RequestMapping(method = RequestMethod.GET)
public String spittles(@RequestParam(value = "max", defaultValue = MAX_LONG_AS_STRING) long max,
@RequestParam(value = "count", defaultValue = "20") int count,
Model model) {
model.addAttribute("spittleList", spittleRepository.findSpittles(Long.MAX_VALUE, 20));
return "spittles";
}
As chrylis said in his answer annotation take a compile-time constant. 正如chrylis在他的答案注释中所说的那样,需要编译时常量。 This may not be the solution you are looking for but to solve the problem at hand, Long.MAX_VALUE
equals 9223372036854775807
这可能不是您正在寻找的解决方案,但要解决手头的问题, Long.MAX_VALUE
等于9223372036854775807
So you can do like this: 所以你可以这样做:
@RequestMapping(method = RequestMethod.GET)
public String spittles(@RequestParam(value = "max",defaultValue = "9223372036854775807") Long max,
@RequestParam(value = "count", defaultValue = "20") int count,
Model model){
model.addAttribute("spittleList",spittleRepository.findSpittle(max,count));
return "spittles";
}
It's not a compile-time constant; 它不是编译时常量; Long.toString()
isn't evaluated until runtime. 直到运行时才评估Long.toString()
。 You'll need to inline it (though it's usually better to omit it entirely if possible, and the new QueryDSL support might make building the repository query simpler). 您需要内联它(尽管通常最好省略它,如果可能的话,新的QueryDSL支持可能会使构建存储库查询更简单)。
关于什么:
@RequestParam(defaultValue = Long.MAX_VALUE + "") long max
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.