Optional long parameter ‘beginDateLong’ is present but cannot be translated into a null value due to being declared as a primitive type.
0.过程
使用SSM框架是controller层接收参数,前台传入时间戳,controller层接收的参数报错。
我当时的写法如下:
@ResponseBody
@RequestMapping(value = "/getdata", method = RequestMethod.GET)
public JSONArray getdata(@Param(value = "beginTime") long beginTime,
@Param(value = "endTime") long endTime)
前台的请求是这样的结构:
http://localhost:4200/energyreport/energysumstruct/getdata?beginTime=1620950400000&endTime=1621468800000
然后就把代码的数据类型改了改,改成下面的这样
@ResponseBody
@RequestMapping(value = "/getdata", method = RequestMethod.GET)
public JSONArray getdata(@Param(value = "beginTime") long beginTime,
@Param(value = "endTime") long endTime)
然后就正常了。
总结:
改用封装数据类型接收参数。如int就用Integer,long使用Long。