axios ---- 请求方式
入门案例
1. axios入门案例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>axios入门案例</title>
</head>
<body>
<script src="../js/vue.js"></script>
<script src="../js/axios.js"></script>
<!-- 使用步骤:
1.导入js函数类库
2.发起Ajax请求,之后业务处理-->
<div id="app" v-text="info">
</div>
<script>
/* axios请求方式:
1.请求类型
1.get 执行查询业务
2.post 执行form表单提交(登录/新增)
3.put 执行修改操作
4.delete 执行删除业务时
2. axios语法
axios.get("url地址信息","参数信息")
.then(function(args){
})
3. 关于args参数说明
axios为了统筹返回值的获取方式,
将所有的数据封装为promise对象
*/
/* 案例一:利用axios获取后台用户列表信息
url: http://localhost:8080/findAll */
axios.get('http://localhost:8080/findAll')
.then(function(promise){
console.log(promise)
console.log(promise.data)
});
/* 写法二:
const app = new Vue({
el:"#app",
data:{
info: ''
},
mounted:function(){
axios.get('http://localhost:8080/findAll').then(
a => (
this.info = a.data
)
).catch(function(e){
console.log(e)
})
}
}); */
</script>
</body>
</html>
package com.jt.controller;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin //开启跨域机制
public class UserController {
@Autowired
private UserService