uniRequest.post('/orderParking',{
parkingRecord:this.ParkingRecord
})
我刚开始只是写@RequestBody ParkingRecord parkingRecord
一直获取的都是null,
直到用了Map标签才终于获取到参数了
@RequestMapping(value = "/orderParking",produces="application/json",method = RequestMethod.POST)
public R orderParking(@RequestBody Map<String,ParkingRecord> parkingRecord)
获取到map的key,就可以获取值了
@RequestMapping(value = "/orderParking",produces="application/json",method = RequestMethod.POST)
public R orderParking(@RequestBody Map<String,ParkingRecord> parkingRecord){
System.out.print(parkingRecord.toString());
//获取当前时间
Date date = new Date();
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
Timestamp timestamp = Timestamp.valueOf(nowTime);
ParkingRecord parkingRecord1 = parkingRecord.get("parkingRecord");
parkingRecord1.setStartTime(timestamp);
boolean res = parkingRecordService.save(parkingRecord1);
Map<String, Object> map = new HashMap<>();
map.put("res",res);
map.put("mes","预约成功");
return R.ok(map);
}
有人说是前后端参数名称不一致:在实体类的属性上加一个注解
然而这个没有解决我的问题
@JsonProperty(value = "car_license")
private String carLicense;
也有人说是因为lombok的问题,自己用idea的快捷键生成,但也没有解决,
再就是实体类的属性名不符合java规范问题:我刚开始是car_lincese这样命名,都需要改为驼峰式命名,carLinces