前端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();
}
文章详细描述了前端使用Vue.js的axios库进行GET请求,附带单个参数,以及如何通过POST方法传递对象至后端Java接口,涉及SpringMVC的@PathVailable和@GetMapping注解,以及@RequestBody用于接收JSON对象。
1718

被折叠的 条评论
为什么被折叠?



