Axios get请求


//前端页面

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Axios第一个入门程序</title>
<!--引入axios的相关依赖-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>

</body>
<script>
// axios.get(url).then(data).catch(err)
//定义一个URL
var URL = "http://127.0.0.1:8083/LQ/axios/findAll"
//get请求
//注意?username=范冰冰&password=123321&email=fanbingbing@163.com是前端传给后端的数据
//后端接收属性名必须与前端传值属性名一致 (不一致传输数据后端为空)
axios.get(URL+"?id=6&username=范冰冰&password=123321&email=fanbingbing@163.com")//发送请求的url
.then(function (response) {
console.log(response)
console.log(response.data)
console.log(response.data[0])
})//响应回来触发的回调函数
.catch(function (error)
{
console.log(error)
});//请求出现错误时回调函数
</script>
</html>


//后端代码
@GetMapping("findAll")
@CrossOrigin//允许请求跨域
public List<Users> findAll(Integer id,String username,String password,String email){
List<Users> users=new ArrayList<>();
users.add(new Users(1,"李云迪","123456","liyundi@163.com"));
users.add(new Users(2,"迪丽热巴","123456","dilireba@163.com"));
users.add(new Users(3,"古力娜扎","123456","gulinazha@163.com"));
users.add(new Users(4,"韩雪","123456","hanxue@163.com"));
users.add(new Users(5,"宋祖儿","123456","songzur@163.com"));
users.add(new Users(id,username,password,email));
System.out.println("id ="+id);
System.out.println("username="+username);
System.out.println("password="+password);
System.out.println("email="+email);
return users;
}
 
posted @ 2020-05-19 15:01  葵儿啊  阅读(74)  评论(0编辑  收藏
/*粒子线条,鼠标移动会以鼠标为中心吸附的特效*/