欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法

 更新時(shí)間:2018年08月21日 15:05:44   作者:八戒愛編程  
今天小編就為大家分享一篇ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

今天做了一個(gè)ajax動(dòng)態(tài)查詢數(shù)據(jù)庫的小Demo,又重新學(xué)習(xí)了一下ajax的一些知識(shí)。在此和大家分享一下......

啥都別說了,先上代碼

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ù)庫中的數(shù)據(jù)并更新........

以上這篇ajax動(dòng)態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺(tái)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論