文章詳情頁(yè)
ajax動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)數(shù)據(jù)并顯示在前臺(tái)的方法
瀏覽:213日期:2022-06-11 13:09:26
今天做了一個(gè)ajax動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)的小Demo,又重新學(xué)習(xí)了一下ajax的一些知識(shí)。在此和大家分享一下......
啥都別說(shuō)了,先上代碼
Controller層
查詢總用戶數(shù)
@RequestMapping(value = "/findTotalUsers.do",method = RequestMethod.GET) public @ResponseBody Long findTotalUsers(){ ModelAndView modelAndView = new ModelAndView(); Long sum = personService.findTotalUsers(); System.out.println(sum+"...................................."); modelAndView.addObject("sum",sum); return sum; }Service層
public Long findTotalUsers() { return personDao.findTotalUsers(); }Dao層
public Long findTotalUsers() { String hql = "select count(*) from Person"; return (Long) this.getSessionFactory().getCurrentSession().createQuery(hql).uniqueResult(); }ajax代碼
<script src="../js/jquery-1.8.3.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready( function ajaxRePost(url,params){ var message = ""; var options={ type:"GET", url:"${pageContext.request.contextPath}/person/findTotalUsers.do", data:{}, async:false, success:function (msg) { message=msg; } }; $.ajax(options); alert(message);// debugger; $("#count").text(message); return message; } ) </script>
結(jié)果就是在Total Users 動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)中的數(shù)據(jù)并更新........
以上這篇ajax動(dòng)態(tài)查詢數(shù)據(jù)庫(kù)數(shù)據(jù)并顯示在前臺(tái)的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持。
標(biāo)簽:
Ajax
上一條:通過(guò)Ajax請(qǐng)求動(dòng)態(tài)填充頁(yè)面數(shù)據(jù)的實(shí)例下一條:ajax實(shí)現(xiàn)從后臺(tái)拿數(shù)據(jù)顯示在HTML前端的方法
相關(guān)文章:
1. AJAX檢測(cè)用戶名是否存在的方法2. 關(guān)于異步請(qǐng)求ajax原理以及原生Ajax、$.ajax的基本使用詳解3. Spring MVC+ajax進(jìn)行信息驗(yàn)證的方法4. 解決SpringMVC、tomcat、Intellij idea、ajax中文亂碼問(wèn)題5. 使用Ajax實(shí)現(xiàn)進(jìn)度條的繪制6. Ajax實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)7. 爬取今日頭條Ajax請(qǐng)求8. Ajax實(shí)現(xiàn)文件上傳功能(Spring MVC)9. ASP.NET MVC使用JSAjaxFileUploader插件實(shí)現(xiàn)單文件上傳10. springmvc 結(jié)合ajax批量新增的實(shí)現(xiàn)方法
排行榜

網(wǎng)公網(wǎng)安備