通过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代码

    

 

 

你可能感兴趣的:(通过ajax查询数据库数据显示在前台)