前端js——get 请求 加 单个参数
this.$request.get('/hotel/selectById/' + this.hotelId).then(res => {
this.hotel = res.data || {}
this.value = res.data.star || 0
})
后端java —— @PathVailable
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Hotel hotel = hotelService.selectById(id);
// System.out.println(hotel);
return Result.success(hotel);
}
前端js——post 传递 对象
this.$request.post('/collect/saveCollect', {
// 传 collect 对象
userId: this.user.id,
hotelId: this.hotelId,
typeId: typeId,
// time: new Date()
})
后端java——@RequestBody
/**
* 小程序收藏 && 取消收藏
*/
@PostMapping("/saveCollect")
public Result saveCollect(@RequestBody Collect collect) {
collectService.saveCollect(collect);
return Result.success();
}