①如何通过axios发送一个携带路径参数的请求?
// 引入axios
import axios from 'axios';
// 假设userId是你要动态替换的值
const userId = 123;
// 直接在URL中使用模板字符串
axios.get(`https://api.example.com/users/${userId}`)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error('Error:', error);
});
②如何在后端的controller层,接收请求中的路径参数?
使用@PathVariable注解,来接收路径参数: