Vue實(shí)現(xiàn)學(xué)生管理功能
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)學(xué)生管理的具體代碼,供大家參考,具體內(nèi)容如下


難點(diǎn)
- 學(xué)生新建與學(xué)生編輯功能都用的一個(gè)組件,如何對其進(jìn)行判斷校驗(yàn)。
- 對用戶輸入進(jìn)行校驗(yàn),非空判斷。
- 向服務(wù)器發(fā)送JSON數(shù)據(jù),后端對JSON數(shù)據(jù)的轉(zhuǎn)換。
- 三層架構(gòu)中,各層功能劃分
- 使用注解對學(xué)生數(shù)據(jù)進(jìn)行操作
整體難度一般,但是小點(diǎn)兒比較多,綜合性強(qiáng)。
例如我用axios像后端發(fā)送post時(shí)候,很容易忽略格式。
前后端數(shù)據(jù)交互時(shí)候,能傳大就傳大,數(shù)據(jù)越完整,數(shù)據(jù)表現(xiàn)越強(qiáng)
拿到后端數(shù)據(jù)時(shí)候,拆包層級要分清。
部分代碼
Vue.js
<script>
let app = new Vue({
el:"#app",
data:{
currentPage:1, //當(dāng)前頁
pageSize:10, //每頁顯示條數(shù)
total:0, //總記錄數(shù);
list:[],//當(dāng)前頁數(shù)據(jù)
//綁定學(xué)生信息
student:{
name:"",
age:""
}
},
methods:{
pager:function(num){
this.currentPage = num;
this.getData();
},
getData:function () {
axios.post("/StudentManager/showAllServlet?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize).then((resp) => {
this.list = resp.data.datas;
this.total = resp.data.total;
});
},
add:function () {
if (this.student.id === undefined) {
axios.post("/StudentManager/addStudentServlet", this.student).then((resp) =>{
if (resp.data.flag){
this.getData();
}else {
alert("添加失敗!");
}
});
}else {
axios.post("/StudentManager/updateStudentServlet", this.student).then((resp)=>{
if (resp.data.flag){
this.getData();
}else {
alert("修改失敗!");
}
});
}
},
deleteStudent:function (id) {
axios.post("/StudentManager/deleteStudentServlet?id="+id).then((resp)=>{
if (resp.data.flag){
this.getData();
}else {
alert("刪除失敗!");
}
});
},
findById:function (id) {
axios.post("/StudentManager/findByIdStudentServlet?id=" + id).then((resp)=>{
this.student = resp.data;
});
}
},
mounted:function () {
this.getData();
}
});
</script>
顯示分頁學(xué)生信息
// Servlet
String currentPage = request.getParameter("currentPage");
String pageSize = request.getParameter("pageSize");
PageBean<Student> pageBean = showAllStudentService.showAllStudent(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(pageBean);
response.getWriter().write(json);
// Service
@Test
@Override
public PageBean<Student> showAllStudent(int currentPage, int pageSize) {
PageHelper.startPage(currentPage, pageSize);
SqlSession sqlSession = SqlSessionUtils.getSqlSession(false);
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
List<Student> students = mapper.showStudent();
PageInfo<Student> pageInfo = new PageInfo<>(students);
long total = pageInfo.getTotal();
int pages = pageInfo.getPages();
PageBean<Student> pageBean = new PageBean<>(total, students, pages);
sqlSession.close();
return pageBean;
}
// Dao
/**
* 首頁顯示所有學(xué)生
* @return 學(xué)生列表
*/
@Select("SELECT * FROM student")
List<Student> showStudent();
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
elementUI如何動(dòng)態(tài)給el-tree添加子節(jié)點(diǎn)數(shù)據(jù)children詳解
element-ui 目前基本成為前端pc網(wǎng)頁端標(biāo)準(zhǔn)ui框架,下面這篇文章主要給大家介紹了關(guān)于elementUI如何動(dòng)態(tài)給el-tree添加子節(jié)點(diǎn)數(shù)據(jù)children的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
vue3+ts+pinia+vant項(xiàng)目搭建詳細(xì)步驟
最近公司想重構(gòu)一個(gè)項(xiàng)目,這里給大家總結(jié)下,這篇文章主要給大家介紹了關(guān)于vue3+ts+pinia+vant項(xiàng)目搭建的詳細(xì)步驟,文中通過圖文及代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09
使用Vue3和p5.js實(shí)現(xiàn)交互式圖像動(dòng)畫
這篇文章主要介紹了如何用Vue3和p5.js打造一個(gè)交互式圖像動(dòng)畫,文中給出了詳細(xì)的代碼示例,本代碼適用于需要在網(wǎng)頁中實(shí)現(xiàn)圖像滑動(dòng)效果的場景,例如圖片瀏覽、相冊展示等,感興趣的小伙伴跟著小編一起來看看吧2024-06-06
vue2 mint-ui loadmore實(shí)現(xiàn)下拉刷新,上拉更多功能
這篇文章主要介紹了vue2 mint-ui loadmore實(shí)現(xiàn)下拉刷新,上拉更多功能,需要的朋友可以參考下2018-03-03

