day45-46-Vue+ElementUI實現學生管理

Vue+ElementUI實現學生管理

代碼: qiushiju/java2313_vue_elementui_crud (gitee.com)

一、思考

  1. 考慮需求(登錄,查詢全部,基本增刪改查,分頁,搜索,批量)

    image-20231207170514721
image-20231207170737870
  1. 設計數據庫
  2. 搭建項目
    1. 后端項目(day39_springboot_curd)已經完成
    2. 前端項目(暫無)ps:前端寫的接口數據 需要和后端一致

二、搭建前端項目

2.1 使用vue-cli創建項目,選擇router,vuex

2.2 安裝所需axios,elementui

# 安裝依賴
npm install --save axios vue-axios
npm i element-ui -S
// 在main.js中配置axios,element
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);// axios
import axios from "axios";
axios.defaults.baseURL = 'http://localhost:8888'// 添加Axios響應攔截器
axios.interceptors.response.use(function (response) {//console.log('響應攔截',response)return response.data;
}, function (error) {console.log(error)
});

2.3 自帶About,HomeView,HelloWorld組件刪除

三、登錄頁

考慮: 項目默認訪問首頁是登錄頁.怎么實現?

解決: 在路由表中定義/路徑匹配Login.vue

App.vue中只保留一個路由 出口<router-view/>

const routes = [{path: '/',component: View1Login}
]

登錄頁View1Login.vue

<template>
<div><el-row class="c1"><el-col class="c1" :span="6" :offset="9"><div class="c2"><el-form ref="form" :model="stu" label-width="80px"><el-form-item label="用戶名"><el-input v-model="stu.sname"></el-input></el-form-item><el-form-item><el-button type="primary" @click="onSubmit">登錄</el-button></el-form-item></el-form></div></el-col></el-row>
</div>
</template><script>
import axios from "axios";
export default {name: "View1Login",data(){return  {stu:{sname:""}}},methods:{onSubmit(){// axios.post('/stu/login',{},{//   params:{//     username:this.stu.sname//   }// })// console.log(this.stu.sname)axios.post('/stu/login',{sname:this.stu.sname}).then(ret => {if (ret.code==20000){this.$message({message:"登錄成功",type:"success",duration:700})// TODO 跳轉頁面}else{this.$message({message:"登錄失敗",type:"error",duration:700})}})}}
}
</script><style scoped>
.c1 {margin-top: 150px;
}
.c2{border: 2px #2c3e50 solid;
}
</style>

擴展: 輸入框輸入完,提示該人是否注冊


登錄成功后,跳轉主頁

onSubmit(){axios.post('/stu/login',{sname:this.stu.sname}).then(ret => {if (ret.code==20000){this.$message({message:"登錄成功",type:"success",duration:700})// 登陸成功 ,要跳轉主頁this.$router.push('/admin')}else{this.$message({message:"登錄失敗",type:"error",duration:700})}})}

image-20231208094942042

四、主頁

思考:

  1. 登錄成功后,App.vue頁面切換成主頁
  2. 主頁面需要容器布局,在右側main主頁內容這里還能 再切換其后頁面

首先,創建View2Admin.vue主頁,布局效果

<template>
<div><el-container><el-header style="text-align: right; font-size: 20px"><span>王小虎</span></el-header><el-container><el-aside width="200px"><el-menu><el-submenu index="1"><template slot="title"><i class="el-icon-message"></i>導航一</template><el-menu-item index="1-1">選項1</el-menu-item><el-menu-item index="1-2">選項2</el-menu-item></el-submenu><el-submenu index="2"><template slot="title"><i class="el-icon-menu"></i>導航二</template><el-menu-item index="2-1">選項1</el-menu-item><el-menu-item index="2-2">選項2</el-menu-item></el-submenu></el-menu></el-aside><el-container><el-main>Main</el-main><el-footer>? 2023 Taotie Copyright</el-footer></el-container></el-container></el-container>
</div>
</template><script>
export default {name: "View2Admin"
}
</script><style scoped>
.el-header, .el-footer {background-color: #3c8dbc;color: #333;text-align: center;line-height: 60px;
}.el-aside {background-color: #2f4050;color: white;text-align: center;line-height: 200px;height: 650px;
}.el-main {background-color: #E9EEF3;color: #333;text-align: center;line-height: 160px;
}body > .el-container {margin-bottom: 40px;
}.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {line-height: 260px;
}.el-container:nth-child(7) .el-aside {line-height: 320px;
}
</style>

image-20231208094959147

五、用戶名

  1. 現在vuex中設置用戶名變量
  2. 登錄時存入state
  3. 主頁中取出

// vuex

export default new Vuex.Store({state: {username:"" // 設置變量名},mutations: {setUsername(state,v){  // 提供一個改變用戶名的方式state.username = v;}}
})

// 登錄時存入state

axios.post('/stu/login',{sname:this.stu.sname}).then(ret => {if (ret.code==20000){this.$message({message:"登錄成功",type:"success",duration:700})// 存儲用戶名this.$store.commit('setUsername',ret.data.sname)// 登陸成功 ,要跳轉主頁this.$router.push('/admin')}else{this.$message({message:"登錄失敗",type:"error",duration:700})}})

// 主頁中取出

<script>
import {mapState}  from 'vuex'
export default {name: "View2Admin",// computed:{//   username(){//     return this.$store.state.username//   }// }computed:mapState(['username'])
}
</script>

六、退出按鈕

    <el-header style="text-align: right; font-size: 20px"><span>{{username}}</span> &nbsp;&nbsp;<span><el-button @click="logout" type="warning" size="small">退出</el-button></span></el-header>
  methods:{logout(){this.$router.push("/")}}

七、歡迎頁

登錄成功,跳轉主頁,主頁先不展示數據,而是展示歡迎頁

創建歡迎頁,引入圖片

<template>
<div><img width="700px" src="../assets/bgm.jpg" alt="背景圖">
</div>
</template><script>
export default {name: "View3Welcome"
}
</script><style scoped></style>

Admin.vue中設置路由出口

image-20231208102429999

router/index.js路由表給admin設置子路由,目的是訪問主頁時,默認跳轉至歡迎頁

image-20231208102453451

image-20231208102247271

八、學生列表

思路: 點擊左邊菜單,路由到Admin的內部(即,子路由),分頁展現所有學生信息

// 創建學生信息頁,寫table組件展示數據,在生命周期函數發請求查數據,給data中變量賦值

<template>
<div>
<!--  卡片-->
<el-card :body-style="{ padding: '20px',height:'400px' }"><!-- TODO: 表頭行高度需要修改!!:header-row-style設置無效!! --><el-table:data="stuList"style="width: 100%"border:header-row-style="{ height: '5px' }"><el-table-columntype="selection"width="55"></el-table-column><!-- label是列名,prop是對象的屬性  --><el-table-columnlabel="學號"prop="id"width="180"></el-table-column><el-table-columnprop="sname"label="姓名"width="180"></el-table-column><el-table-columnprop="age"label="年齡"sortable></el-table-column><el-table-columnprop="sex"label="性別"></el-table-column><el-table-columnprop="score"label="分數"></el-table-column><el-table-columnprop="birthday"label="生日"></el-table-column></el-table>
</el-card>
</div>
</template><script>
import axios from "axios";
export default {name: "View4StuInfo",data(){return {stuList:[]}},// 定義生命周期函數,頁面加載完即展現數據created() {axios.get('/stu/list',{params:{pageNum:1  // 默認訪問第一頁}}).then(ret => {if (ret.code == 20000){// ret.data是后端返回的PageInfoconsole.log(ret.data)this.stuList= ret.data.list;} else {this.$message.error('后臺請求錯誤')}})}
}
</script><style scoped></style>

// 主頁面,左側菜單,點擊路由跳轉至學生頁

image-20231208111025604

// 經過路由表映射,到admin的子路由中

image-20231208111059040

九、分頁查詢

1)設置分頁組件

2) 設置對應的 函數

<template>
<div>
<!--  卡片-->
<el-card :body-style="{ padding: '20px',height:'400px' }"><!-- TODO: 表頭行高度需要修改!!:header-row-style設置無效!! --><el-table:data="stuList"style="width: 100%"border:header-row-style="{ height: '5px' }"height="370px"><el-table-columntype="selection"width="55"></el-table-column><!-- label是列名,prop是對象的屬性  --><el-table-columnlabel="學號"prop="id"width="180"></el-table-column><el-table-columnprop="sname"label="姓名"width="180"></el-table-column><el-table-columnprop="age"label="年齡"sortable></el-table-column><el-table-columnprop="sex"label="性別"></el-table-column><el-table-columnprop="score"label="分數"></el-table-column><el-table-columnprop="birthday"label="生日"></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-buttonsize="mini">編輯</el-button><el-buttonsize="mini"type="danger">刪除</el-button></template></el-table-column></el-table><div><!--@size-change="handleSizeChange"      頁面大小改變會觸發函數@current-change="handleCurrentChange"當前頁改變 觸發函數:current-page.sync="currentPage":page-sizes="[3, 6, 9]"   演示每頁大小列表:page-size="pageSize"     綁定頁面大小,下方data中定義變量layout="sizes,prev, pager, next"  外觀顯示效果:total="total">   總條數,下方data中定義變量--><el-paginationbackground@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page.sync="currentPage":page-sizes="[3, 6, 9]":page-size="pageSize"layout="sizes,prev, pager, next":total="total"></el-pagination></div>
</el-card>
</div>
</template><script>
import axios from "axios";
export default {name: "View4StuInfo",data(){return {stuList:[],currentPage: 1,pageSize: 3,total: 0,}},methods:{// 抽取查詢數據的方法,可以復用getData(){axios.get('/stu/list',{params:{pageNum:this.currentPage,  // 默認訪問第一頁pageSize: this.pageSize}}).then(ret => {if (ret.code == 20000){// ret.data是后端返回的PageInfoconsole.log(ret.data)this.stuList= ret.data.list;this.total=ret.data.total;} else {this.$message.error('后臺請求錯誤')}})},// 頁面大小變化時,改變pageSizehandleSizeChange(val) {this.pageSize = val;this.getData();},// 當前頁變化,即跳轉頁面時handleCurrentChange(val) {this.currentPage = val;// 重新查詢當前頁數據this.getData();},},// 定義生命周期函數,頁面加載完即展現數據created() {this.getData();}
}
</script><style scoped></style>

image-20231208113907620

十、添加

image-20231211174530052

需求:

1)表格上方設置添加按鈕

2)彈出彈出層對話框

3)其中設置表單

4)點擊保存,插入數據庫

5)對話框隱藏,查詢最新數據


在StuInfo.vue中添加對話框和對應的js

<template>
<div>
<!--  卡片-->
<el-card :body-style="{ padding: '20px',height:'400px' }"><div style="text-align: left"><el-button type="danger">批量刪除</el-button><!-- 顯示/隱藏對話框,通過變量 --><el-button type="primary" @click="addDialogVisible = true">添加</el-button></div><!-- 添加對話框,默認是隱藏 --><el-dialogtitle="添加":visible.sync="addDialogVisible"width="30%":before-close="handleClose"><el-form :model="stu" status-icon :rules="rules" ref="stu" label-width="100px" class="demo-stu"><el-form-item label="用戶名" prop="sname"><el-input type="text" v-model="stu.sname" autocomplete="off"></el-input></el-form-item><el-form-item label="年齡" prop="age"><!-- TODO: .number是修飾符,輸入的直接就是數字 --><el-input type="text" v-model.number="stu.age" autocomplete="off"></el-input></el-form-item><el-form-item label="性別" prop="sex"><!--todo: 單選框獲得的值是什么?是label的值? 結論!是label值--><el-radio-group v-model="stu.sex"><el-radio label=""></el-radio><el-radio label=""></el-radio></el-radio-group></el-form-item><el-form-item label="分數" prop="score"><el-input type="text" v-model="stu.score" autocomplete="off"></el-input></el-form-item><el-form-item label="生日" prop="birthday"><el-col :span="11"><el-date-picker type="date" placeholder="選擇日期" v-model="stu.birthday" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker></el-col></el-form-item><el-form-item><el-button @click="addDialogVisible = false">取 消</el-button><el-button type="primary" @click="submitForm('stu')">提交</el-button></el-form-item></el-form></el-dialog><!-- 表格渲染數據: 省略 --><!-- 分頁: 省略 --></div>
</el-card>
</div>
</template><script>
import axios from "axios";
export default {name: "View4StuInfo",data(){// 自定義校驗年齡var checkAge = (rule, value, callback) => {if (!value) {return callback(new Error('年齡不能為空'));}if (!Number.isInteger(value)) {callback(new Error('請輸入數字值'));} else {if (value < 18) {callback(new Error('必須年滿18歲'));} else {// 校驗通過放行!!callback();}}};return {stuList:[],currentPage: 1,pageSize: 3,total: 0,addDialogVisible: false,stu:{sname:"",age:0,sex:"",score:0.0,birthday:""},rules: {age: [{ validator: checkAge, trigger: 'blur' }]}}},methods: {// 抽取查詢數據的方法,可以復用getData() {axios.get('/stu/list', {params: {pageNum: this.currentPage,  // 默認訪問第一頁pageSize: this.pageSize}}).then(ret => {if (ret.code == 20000) {// ret.data是后端返回的PageInfoconsole.log(ret.data)this.stuList = ret.data.list;this.total = ret.data.total;} else {this.$message.error('后臺請求錯誤')}})},// 頁面大小變化時,改變pageSizehandleSizeChange(val) {this.pageSize = val;this.getData();},// 當前頁變化,即跳轉頁面時handleCurrentChange(val) {this.currentPage = val;// 重新查詢當前頁數據this.getData();},handleClose(done) {this.$confirm('確認關閉?').then(_ => {done();}).catch(_ => {});},// 提交表單,并隱藏對話框submitForm(formName) {this.$refs[formName].validate((valid) => {if (valid) {console.log("提交表單--->  ",this.stu)// TODO 添加成功! 但是市區不對!//  已解決! 給el-date-picker設置value-format="yyyy-MM-dd"即可axios.post('/stu/add',this.stu).then(ret =>{console.log(ret)})} else {console.log('error submit!!');return false;}});// 重置當前頁為第一頁,this.currentPage = 1;// 查詢最新數據,從第一頁查this.getData();// 隱藏對話框this.addDialogVisible = false;// 對話框清空this.$refs.stu.resetFields()},},// 定義生命周期函數,頁面加載完即展現數據created() {this.getData();}
}
</script><style scoped></style>

問題1: 時區,時間差一天 // 已解決! 給el-date-picker設置value-format="yyyy-MM-dd"即可

問題2:添加表格沒有清空

// 解決方案:對話框清空,注意此處stu是el-form上面定義的ref的值
this.$refs.stu.resetFields()

十一、更新

image-20231211174547519

思路:

1)點擊更新按鈕,彈出對話框

2)對話框回顯數據 ps: elementui-table組件,按鈕事件中自帶屬性scope,觸發按鈕獲得當前行內數據

3)點擊保存

4)對話框隱藏,重新查詢


StuInfo.vue

<template>
<div>
<!--  卡片-->
<el-card :body-style="{ padding: '20px',height:'400px' }"><div style="text-align: left"><el-button type="danger">批量刪除</el-button><!-- 顯示/隱藏對話框,通過變量 --><el-button type="primary" @click="addDialogVisible = true">添加</el-button></div><!-- 添加對話框,默認是隱藏 --><!--更新對話框,默認是隱藏 --><el-dialogtitle="更新":visible.sync="editDialogVisible"width="30%"><el-form :model="stu" status-icon :rules="rules" ref="editStuRef" label-width="100px" class="demo-stu"><el-form-item label="用戶名" prop="sname"><el-input type="text" v-model="stu.sname" autocomplete="off"></el-input></el-form-item><el-form-item label="年齡" prop="age"><el-input type="text" v-model.number="stu.age" autocomplete="off"></el-input></el-form-item><el-form-item label="性別" prop="sex"><el-radio-group v-model="stu.sex"><el-radio label=""></el-radio><el-radio label=""></el-radio></el-radio-group></el-form-item><el-form-item label="分數" prop="score"><el-input type="text" v-model="stu.score" autocomplete="off"></el-input></el-form-item><el-form-item label="生日" prop="birthday"><el-col :span="11"><el-date-picker type="date" placeholder="選擇日期" v-model="stu.birthday" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker></el-col></el-form-item><el-form-item><el-button @click="editDialogVisible = false">取 消</el-button><el-button type="primary" @click="editForm('editStuRef')">更新</el-button></el-form-item></el-form></el-dialog><!-- 表格渲染數據 --><el-table:data="stuList"style="width: 100%"borderheight="340px"><el-table-columntype="selection"width="55"></el-table-column><!-- label是列名,prop是對象的屬性  --><el-table-columnlabel="學號"prop="id"width="180"></el-table-column><el-table-columnprop="sname"label="姓名"width="180"></el-table-column><el-table-columnprop="age"label="年齡"sortable></el-table-column><el-table-columnprop="sex"label="性別"></el-table-column><el-table-columnprop="score"label="分數"></el-table-column><el-table-columnprop="birthday"label="生日"></el-table-column><el-table-column label="操作"><template slot-scope="scope"><el-buttontype="warning"size="mini"@click="handleEdit(scope.$index, scope.row)">編輯</el-button><el-buttonsize="mini"type="danger">刪除</el-button></template></el-table-column></el-table><!-- 分頁 --></div>
</template><script>
import axios from "axios";
export default {name: "View4StuInfo",data(){// 自定義校驗年齡var checkAge = (rule, value, callback) => {if (!value) {return callback(new Error('年齡不能為空'));}if (!Number.isInteger(value)) {callback(new Error('請輸入數字值'));} else {if (value < 18) {callback(new Error('必須年滿18歲'));} else {// 校驗通過放行!!callback();}}};// 數據return {stuList:[],currentPage: 1,pageSize: 3,total: 0,addDialogVisible: false,editDialogVisible:false,stu:{sname:"",age:0,sex:"",score:0.0,birthday:""},rules: {age: [{ validator: checkAge, trigger: 'blur' }]}}},// 函數methods: {// 抽取查詢數據的方法,可以復用// 頁面大小變化時,改變pageSize// 當前頁變化,即跳轉頁面時// 提交添加表單,并隱藏對話框// 處理更新回顯handleEdit(index, row) {this.editDialogVisible = true;this.stu = row},// 提交更新表單,并隱藏對話框editForm(formName) {this.$refs[formName].validate((valid) => {if (valid) {console.log("提交更新表單--->  ",this.stu)axios.put('/stu/edit',this.stu).then(ret =>{if (ret.code == 20000) {// 重置當前頁為第一頁,this.currentPage = 1;// 查詢最新數據,從第一頁查this.getData();}})} else {console.log('error submit!!');return false;}});// 隱藏對話框this.editDialogVisible = false;// 對話框清空this.$refs.editStuRef.resetFields()},},// 定義生命周期函數,頁面加載完即展現數據
}
</script>

問題1: 后端查詢日期到前端顯示少一天!

解決: @JsonFormat(pattern = “yyyy-MM-dd”,timezone = “GMT+8”)

參考解決springboot框架返回前端的日期值少一天_springboot 后端傳給前端的時間不是24小時-CSDN博客

十二、刪除

image-20231211174605778

思路:

1)刪除按鈕

2)彈出確認框,確定刪除,取消

3)確定刪除,發請求攜帶id

4)刪除完重新查詢數據


image-20231211142808829

image-20231211142910357

十三、批量刪除

image-20231211174629974

1)設置復選框改變,獲得選中行數據

image-20231211150256814

2)點擊批量刪除按鈕,發請求

image-20231211150435783

3)后端接收id數組

image-20231211150535084

十四、模糊搜索

image-20231211174503098

需求: 提供根據名字模糊搜索,年齡等值搜索,時間區間搜


思路:

1)設置卡片,卡片中設置 搜索表單

2)點擊搜索,發請求搜索 -->用的還是查詢全部,只不過多帶了一些搜索關鍵詞

3)搜索后數據還在表格 中展現


  <div style="margin-bottom: 10px">
<!--  搜索框卡片--><el-card :body-style="{ padding: '20px',height:'30px'}"><el-form :inline="true" :model="searchModel" status-icon ref="searchModelRef" label-width="100px" class="demo-stu"><el-form-item label="用戶名"prop="sname"><el-input style="width: 200px" size="small" type="text" v-model="searchModel.sname" autocomplete="off"></el-input></el-form-item><el-form-item label="年齡" prop="age"><el-input style="width: 50px" size="small" type="text" v-model.number="searchModel.age" autocomplete="off"></el-input></el-form-item><el-form-item label="生日"><el-col :span="11"><el-form-item prop="birthday1"><el-date-picker size="small" type="date" placeholder="選擇日期" v-model="searchModel.birthday1" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker></el-form-item></el-col><el-col class="line" :span="2">-</el-col><el-col :span="11"><el-form-item prop="birthday2"><el-date-picker size="small" type="date" placeholder="選擇日期" v-model="searchModel.birthday2" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker></el-form-item></el-col></el-form-item><el-form-item><el-button size="small" type="primary" @click="searchSubmit">提交</el-button><el-button size="small" @click="resetSearch('searchModelRef')">重置 </el-button></el-form-item></el-form></el-card></div>
<script>
import axios from "axios";
export default {name: "View4StuInfo",data(){return{// 搜索關鍵詞searchModel:{sname:"",age:0,birthday1:"",birthday2:"",pageSize:3,pageNum:1}}},methods:{//代碼見圖}
}

image-20231211163946789

改動 了getData()函數,從原來只有分頁查詢,改成了帶上模糊關鍵詞查詢

image-20231211164039908


后端查詢全部的接口,變成接收map,map中就包含搜索關鍵詞和分頁數據

image-20231211164139806

mapper做動態sql查詢

image-20231211164241383

總結

  1. 前后端對接注意事項
// 前端發 get,用params
axios.get('/login',{params:{username:this.username,password:this.password,}
}).then(ret =>{})// 后端Controller,方法正常寫兩個變量名接收
@GetMapping("/login")
public R login(String username,String password){}
// 前端發 post
axios.post('/login',{username:this.username,password:this.password,
}).then(ret =>{})// 后端Controller,方法正常寫兩個變量名接收接不到!!!
// 方法參數列表需要用對象,且加@RequestBody
@PostMapping("/login")
public R login(@RequestBody User user){}
  1. 看日志,從日志中 你自己寫過的相關的單詞,變量,屬性,方法等等

  2. axios有響應攔截,確定項目是否配置攔截!! 如果配置了攔截,我們已經在攔截中取出了響應的數據,即axios成功回調函數then中的ret就是獲得的R

  3. 前后端對接

    增前端發post,攜帶數據是json后端@PostMapping,參數列表用json對應的java實體類,配上@RequestBody
    刪一個前端發get,攜帶參數可以 用{param:{id:1}}后端@GetMapping,參數列表用一個基本類型int id接收
    刪多個(批量)方案一:前端發get,攜帶參數可以拼接后端@GetMapping,參數列表用List,配合@RequestParam方案一:前端發post,攜帶參數,直接將數組放在data處后端@PostMapping,參數列表用List,配合@RequestBody	  	
    改前端發post/put,攜帶數據是json后端@PostMapping,參數列表用json對應的java實體類,配上@RequestBody
    查(空參)
    查(簡單參數)前端發post,攜帶json參數后端方法參數列表用對象接收,@RequestBody------前端發get,攜帶{params:{username:'zs',password:'123'}}后端方法參數列表,直接設置(String username,String password)
    查(復雜參數)前端發get,攜帶params參數后端方法參數列表用Map接收,配合@RequestParam
    

    基本上,前端只要使用post發送json,后端就得使用@RequestBody+對象

    前端使用get發送,普通參數,后端 正常接收 ,默認List,Map類型參數需要@RequestParam
    ord){}

```js
// 前端發 post
axios.post('/login',{username:this.username,password:this.password,
}).then(ret =>{})// 后端Controller,方法正常寫兩個變量名接收接不到!!!
// 方法參數列表需要用對象,且加@RequestBody
@PostMapping("/login")
public R login(@RequestBody User user){}
  1. 看日志,從日志中 你自己寫過的相關的單詞,變量,屬性,方法等等

  2. axios有響應攔截,確定項目是否配置攔截!! 如果配置了攔截,我們已經在攔截中取出了響應的數據,即axios成功回調函數then中的ret就是獲得的R

  3. 前后端對接

    增前端發post,攜帶數據是json后端@PostMapping,參數列表用json對應的java實體類,配上@RequestBody
    刪一個前端發get,攜帶參數可以 用{param:{id:1}}后端@GetMapping,參數列表用一個基本類型int id接收
    刪多個(批量)方案一:前端發get,攜帶參數可以拼接后端@GetMapping,參數列表用List,配合@RequestParam方案一:前端發post,攜帶參數,直接將數組放在data處后端@PostMapping,參數列表用List,配合@RequestBody	  	
    改前端發post/put,攜帶數據是json后端@PostMapping,參數列表用json對應的java實體類,配上@RequestBody
    查(空參)
    查(簡單參數)前端發post,攜帶json參數后端方法參數列表用對象接收,@RequestBody------前端發get,攜帶{params:{username:'zs',password:'123'}}后端方法參數列表,直接設置(String username,String password)
    查(復雜參數)前端發get,攜帶params參數后端方法參數列表用Map接收,配合@RequestParam
    

    基本上,前端只要使用post發送json,后端就得使用@RequestBody+對象

    前端使用get發送,普通參數,后端 正常接收 ,默認List,Map類型參數需要@RequestParam

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/214806.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/214806.shtml
英文地址,請注明出處:http://en.pswp.cn/news/214806.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2024美賽備戰2--模型建立(*****必看****)

建模 美賽涉及的建模知識范圍非常廣且深&#xff0c;縱觀美賽真題不難發現&#xff0c;很多的模型 都是讀研或者讀博的時候才會真正深入開始研究&#xff0c;因此&#xff0c;對于做建模的同學來說&#xff0c; 是無法在賽前吃透大量模型的。推薦本科生分兩個步驟去有效準備比賽…

【S32DS RTD實戰】-1.3-S32K3工程生成S19,BIN,Hex文件,以及Post-build steps的妙用

目錄 1 方法一&#xff1a;逐個生成Motorola S-record&#xff08;s19&#xff0c;srec…&#xff09;&#xff0c;Intel HEX&#xff0c;Bin文件 1.1 生成Motorola S-record&#xff08;s19&#xff0c;srec…&#xff09;文件 1.2 生成Intel HEX文件 1.3 生成Bin文件 2 …

python的Streamlit庫的text_input組件

text_input 常用的輸入組件&#xff0c;這里注意記錄一下具體的參數&#xff0c;方便使用 函數簽名 st.text_input(label, value"", max_charsNone, keyNone, type"default", helpNone, autocompleteNone, on_changeNone, argsNone, kwargsNone, *, pla…

【LeetCode】414. 第三大的數

414. 第三大的數 難度&#xff1a;簡單 題目 給你一個非空數組&#xff0c;返回此數組中 第三大的數 。如果不存在&#xff0c;則返回數組中最大的數。 示例 1&#xff1a; 輸入&#xff1a;[3, 2, 1] 輸出&#xff1a;1 解釋&#xff1a;第三大的數是 1 。示例 2&#xf…

計算機服務器中了mkp勒索病毒怎么辦,mkp勒索病毒解密數據恢復

網絡技術的不斷發展&#xff0c;也為網絡安全帶來了威脅&#xff0c;近期云天數據恢復中心的工程師陸續接到很多企業的求助&#xff0c;在本月&#xff0c;很多企業的計算機服務器遭到了mkp勒索病毒攻擊&#xff0c;導致企業計算機系統癱瘓&#xff0c;無法正常工作&#xff0c…

vue生命周期和路由

Vue.js 生命周期是Vue.js實例從創建到銷毀的整個過程中所經過的一系列事件&#xff0c;可以理解為Vue.js的生命周期鉤子函數。在這些生命周期鉤子函數中&#xff0c;你可以添加自定義的邏輯代碼&#xff0c;以便在組件生命周期的不同階段進行不同的操作。Vue.js生命周期共分為八…

Linux的ps簡單實現

原理&#xff1a;遍歷下的/proc/%s/task/%s/status所有文件&#xff0c;兩個%s都為pid號。 注&#xff1a;多線程下&#xff0c;只打印一個pid/task下的所有目錄&#xff0c;即可收集各個線程對應的信息。 $ cat ps.c #include <stdio.h> #include <stdlib.h> #in…

《深入理解計算機系統》學習筆記 - 第四課 - 機器級別的程序

Lecture 05 Machine Level Programming I Basics 機器級別的程序 文章目錄 Lecture 05 Machine Level Programming I Basics 機器級別的程序intel 處理器的歷史和體系結構芯片的構成AMD 公司(Advanced Micro Devices&#xff0c;先進的微型設備) C, 匯編, 機器代碼定義匯編/機器…

2024美賽備戰1--數據處理(數據預處理,異常值處理,預測模型,插值擬合 *****必看****)

1.數據預處理 所謂數據預處理&#xff0c;就是指在正式做題之前對數據進行的一些處理。在有些情 況下&#xff0c;出題方提供的數據或者網上查找的數據并不能直接使用&#xff0c;比如缺少數據甚 至是異常數據&#xff0c;如果直接忽略缺失值&#xff0c;或者沒發現異常數據&am…

angular material mat-error 失效不展示

1.你命名了控制mat-error顯示與否的變量&#xff0c;卻沒有在html里使用 2.mat-error是放在mat-form-field里才生效的&#xff0c;如果 <input matInput required formControlName"phoneNumber" /> 中的phoneNumber其實是valid&#xff0c;通過驗證的&#x…

【KALI】設置靜態IP地址

ip: 192.168.1.10/24 網關&#xff1a;192.168.1.1 DNS&#xff1a;192.168.1.254/etc/network/interfaces原始文件內容為&#xff1a; # This file describes the network interfaces available on your system # and how to activate them. For more information, see inter…

數字圖像處理(實踐篇)二十一 人臉識別

目錄 1 安裝face_recognition 2 涉及的函數 3 人臉識別方案 4 實踐 使用face_recognition進行人臉識別。 1 安裝face_recognition pip install face_recognition 或者 pip --default-timeout100 install face_recognition -i http://pypi.douban.com/simple --trusted-…

川崎ZX-6R確定引進,636它真的來了,3C認證已過。

最新消息&#xff0c;兄弟們&#xff0c;你們期待已久的川崎ZX6R&#xff08;636&#xff09;基本已經確定引進了&#xff0c;官方的3C認證已經通過&#xff0c;那么從3C里面我們可以看到哪幾個信息&#xff1f;產品代號ZX636J就是心心念念的ZX-6R了。 有些小伙伴不太清楚3C認…

t-SNE完整筆記 (附Python代碼)

t-SNE(t-distributed stochastic neighbor embedding)是用于降維的一種機器學習算法&#xff0c;是由 Laurens van der Maaten 和 Geoffrey Hinton在08年提出來。此外&#xff0c;t-SNE 是一種非線性降維算法&#xff0c;非常適用于高維數據降維到2維或者3維&#xff0c;進行可…

laravel定時任務配置手冊

任務調度在 app/Console/Kernel.php 的 schedule 方法中進行定義&#xff1b; 分配多種調度計劃&#xff1a;結合其他一些特定條件&#xff0c;我們可以生成在一周中特定時間運行的任務。舉個例子&#xff0c;在每周一執行命令&#xff1a; 方法 描述 ->cron(* * * * *); …

分配棧空間的三種方式(基于適配qemu的FreeRTOS分析)

1、定義全局的數組 定義的全局數組屬于bss段&#xff0c;相當于把bss段的一部分作為棧空間&#xff0c;棧空間的大小就是數組的大小如果把棧空間放在bss段&#xff0c;則在bss段清零時會多清零一段地址空間 2、在鏈接腳本中指定 用鏈接腳本在所有段的后面增加stack段&#xff…

15:00面試,15:06就出來了,問的問題真變態。。。

剛從小廠出來&#xff0c;沒想到在另一家公司我又寄了。 在這家公司上班&#xff0c;每天都要加班&#xff0c;但看在錢給的比較多的份上&#xff0c;也就不太計較了。但萬萬沒想到5月一紙通知&#xff0c;所有人不準加班了&#xff0c;不僅加班費沒有了&#xff0c;薪資還要降…

基于springboot的大學生兼職信息管理系統(源碼+數據庫+文檔)

摘要 基于Spring Boot的大學生兼職信息管理系統是一個為大學生和兼職公司提供服務的平臺。通過該系統&#xff0c;大學生可以方便地尋找兼職工作機會&#xff0c;而兼職公司可以發布、管理和篩選合適的兼職信息。首先&#xff0c;系統采用了Spring Boot作為開發框架&#xff0…

Ubuntu22.04使能root用戶

一、背景 安裝Ubuntu22.04系統的時候&#xff0c;會要求創建一個用戶&#xff0c;并設置密碼。為方便后續行文&#xff0c;將此用戶稱為user_normal&#xff0c;此密碼稱為normal_pd 安裝Ubuntu22.04系統的時候&#xff0c;沒有出現任何和root有關的設置 Ubuntu22.04安裝完成…

[隴劍杯 2021]日志分析

[隴劍杯 2021]日志分析 題目做法及思路解析&#xff08;個人分享&#xff09; 問一&#xff1a;單位某應用程序被攻擊&#xff0c;請分析日志&#xff0c;進行作答&#xff1a; 網絡存在源碼泄漏&#xff0c;源碼文件名是_____________。(請提交帶有文件后綴的文件名&…