Vue實(shí)現(xiàn)學(xué)生管理功能
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)學(xué)生管理的具體代碼,供大家參考,具體內(nèi)容如下
難點(diǎn)
- 學(xué)生新建與學(xué)生編輯功能都用的一個(gè)組件,如何對(duì)其進(jìn)行判斷校驗(yàn)。
- 對(duì)用戶(hù)輸入進(jìn)行校驗(yàn),非空判斷。
- 向服務(wù)器發(fā)送JSON數(shù)據(jù),后端對(duì)JSON數(shù)據(jù)的轉(zhuǎn)換。
- 三層架構(gòu)中,各層功能劃分
- 使用注解對(duì)學(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í)候,拆包層級(jí)要分清。
部分代碼
Vue.js
<script> let app = new Vue({ el:"#app", data:{ currentPage:1, //當(dāng)前頁(yè) pageSize:10, //每頁(yè)顯示條數(shù) total:0, //總記錄數(shù); list:[],//當(dāng)前頁(yè)數(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>
顯示分頁(yè)學(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 /** * 首頁(yè)顯示所有學(xué)生 * @return 學(xué)生列表 */ @Select("SELECT * FROM student") List<Student> showStudent();
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
elementUI如何動(dòng)態(tài)給el-tree添加子節(jié)點(diǎn)數(shù)據(jù)children詳解
element-ui 目前基本成為前端pc網(wǎng)頁(yè)端標(biāo)準(zhǔn)ui框架,下面這篇文章主要給大家介紹了關(guān)于elementUI如何動(dòng)態(tài)給el-tree添加子節(jié)點(diǎn)數(shù)據(jù)children的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11vue單頁(yè)緩存存在的問(wèn)題及解決方案(小結(jié))
這篇文章主要介紹了vue單頁(yè)緩存存在的問(wèn)題及解決方案(小結(jié)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)根據(jù)hash高亮選項(xiàng)卡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05vue3+ts+pinia+vant項(xiàng)目搭建詳細(xì)步驟
最近公司想重構(gòu)一個(gè)項(xiàng)目,這里給大家總結(jié)下,這篇文章主要給大家介紹了關(guān)于vue3+ts+pinia+vant項(xiàng)目搭建的詳細(xì)步驟,文中通過(guò)圖文及代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09使用Vue3和p5.js實(shí)現(xiàn)交互式圖像動(dòng)畫(huà)
這篇文章主要介紹了如何用Vue3和p5.js打造一個(gè)交互式圖像動(dòng)畫(huà),文中給出了詳細(xì)的代碼示例,本代碼適用于需要在網(wǎng)頁(yè)中實(shí)現(xiàn)圖像滑動(dòng)效果的場(chǎng)景,例如圖片瀏覽、相冊(cè)展示等,感興趣的小伙伴跟著小編一起來(lái)看看吧2024-06-06vue2 mint-ui loadmore實(shí)現(xiàn)下拉刷新,上拉更多功能
這篇文章主要介紹了vue2 mint-ui loadmore實(shí)現(xiàn)下拉刷新,上拉更多功能,需要的朋友可以參考下2018-03-03VUE寫(xiě)一個(gè)簡(jiǎn)單的表格實(shí)例
在本篇文章里小編給大家整理的是關(guān)于VUE中表格的寫(xiě)法實(shí)例以及相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們可以參考下。2019-08-08