Restful果然牛,之前还在想为什么对于以下请求,要用@PathVariable去接参
http://localhost:8000/menu/queryMenu/{menuCode}
而对这种请求竟与post请求接参一样用@RequestParam(“menuCode”)
http://localhost:8000/menu/queryMenu?menuCode=1
(request也可用@RequestBody Menu menu)
学了Vue的axios后发现,Vue的提交方式默认
axios({
url: 'http://localhost:8000/menu/queryMenu',
params: {
menuCode: '1'
}
}).then(result=>{
console.log(result);
})
就是将menuCode: '1’拼接到?后面变成
http://localhost:8000/home/queryMenu?menuCode=1
而post请求:
axios.post('http://localhost:8000/menu/addMenu',{
menuCode: 2,
menuName: '我的',
order: 2
}).then(() => {
console.log('success');
}).catch(e=>{
console.log('error');
})
只不过是没有用param转换成拼接方式。所以携带方式不一样,没有?后面的一串
这样一来,对Restful接口中,怎么去接参就能记得很清楚了。