ajax動態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺的方法
更新時間:2018年08月21日 15:05:44 作者:八戒愛編程
今天小編就為大家分享一篇ajax動態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
今天做了一個ajax動態(tài)查詢數(shù)據(jù)庫的小Demo,又重新學習了一下ajax的一些知識。在此和大家分享一下......
啥都別說了,先上代碼
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 動態(tài)查詢數(shù)據(jù)庫中的數(shù)據(jù)并更新........
以上這篇ajax動態(tài)查詢數(shù)據(jù)庫數(shù)據(jù)并顯示在前臺的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
ajax異步回調(diào)函數(shù)中給外部變量賦值的問題探討
ajax異步回調(diào)函數(shù)中給外部變量賦值的問題在本文將為大家詳細探討下,感興趣的朋友可以參考下2013-09-09
ajax請求后臺接口數(shù)據(jù)與返回值處理js的實例講解
今天小編就為大家分享一篇ajax請求后臺接口數(shù)據(jù)與返回值處理js的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

