今天做了一个ajax动态查询数据库的小Demo,又重新学习了一下ajax的一些知识。在此和大家分享一下......
啥都别说了,先上代码
Controller层
查询总用户数
@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代码