Vue實(shí)現(xiàn)學(xué)生管理功能
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)學(xué)生管理的具體代碼,供大家參考,具體內(nèi)容如下
整體難度一般,但是小點(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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python 寫(xiě)一個(gè)文件分發(fā)小程序2. Python importlib模塊重載使用方法詳解3. python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別4. Vue3中使用this的詳細(xì)教程5. Python 利用flask搭建一個(gè)共享服務(wù)器的步驟6. Python中Anaconda3 安裝gdal庫(kù)的方法7. 用python對(duì)oracle進(jìn)行簡(jiǎn)單性能測(cè)試8. Python自動(dòng)化之定位方法大殺器xpath9. Python本地及虛擬解釋器配置過(guò)程解析10. Python Selenium破解滑塊驗(yàn)證碼最新版(GEETEST95%以上通過(guò)率)
