是这样的:
public DataGrid userDg(int page, int rows){
DataGrid dg = new DataGrid(); String hql0 = "from User t where 1=1";
String hql = " select count(*) "+hql0; List<User> l0=userDAO.find(hql0, page, rows);
List<User> nl = new ArrayList<User>();
if (l0 != null && l0.size() > 0) {
for (User user : l0) {
User tempUser = new User();
BeanUtils.copyProperties(user, tempUser);
nl.add(tempUser);
}
}
dg.setRows(nl); Long total = userDAO.count(hql);
dg.setTotal(total); return dg;
}userdao里面的:
public List<User> find(String hql, int page, int rows) {
Query q = this.getSession().createQuery(hql);
return q.setFirstResult((page - 1) * rows).setMaxResults(rows).list();
} public Long count(String hql) {
Query q = this.getSession().createQuery(hql);
return (Long) q.uniqueResult();
}
看着是没什么问题呀:得到的结果却是这样的:{
    "rows": [
        {
            "address": "",
            "birthday": null,
            "company": "",
            "email": "[email protected]",
            "gender": "女",
            "id": 0,
            "lastlogindate": {
                "date": 5,
                "day": 0,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367683200000,
                "timezoneOffset": -480,
                "year": 113
            },
            "msn": "",
            "number": "123456",
            "password": "123456",
            "phone": "",
            "qq": "",
            "realname": "admin",
            "registerdate": {
                "date": 5,
                "day": 0,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367683200000,
                "timezoneOffset": -480,
                "year": 113
            },
            "role": "admin"
        },
        {
            "address": "",
            "birthday": null,
            "company": "",
            "email": "[email protected]",
            "gender": "男",
            "id": 0,
            "lastlogindate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "msn": "",
            "number": "123",
            "password": "123456",
            "phone": "",
            "qq": "",
            "realname": "sdfd",
            "registerdate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "role": "普通用户"
        },
        {
            "address": "",
            "birthday": null,
            "company": "",
            "email": "[email protected]",
            "gender": "女",
            "id": 0,
            "lastlogindate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "msn": "",
            "number": "123235134",
            "password": "123456",
            "phone": "",
            "qq": "",
            "realname": "sfdh",
            "registerdate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "role": "普通用户"
        },
        {
            "address": "",
            "birthday": null,
            "company": "",
            "email": "[email protected]",
            "gender": "女",
            "id": 0,
            "lastlogindate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "msn": "",
            "number": "2132435",
            "password": "123456",
            "phone": "",
            "qq": "",
            "realname": "dfgfh",
            "registerdate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "role": "普通用户"
        },
        {
            "address": "",
            "birthday": null,
            "company": "",
            "email": "[email protected]",
            "gender": "男",
            "id": 0,
            "lastlogindate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "msn": "",
            "number": "244368",
            "password": "123456",
            "phone": "",
            "qq": "",
            "realname": "sdf",
            "registerdate": {
                "date": 6,
                "day": 1,
                "hours": 0,
                "minutes": 0,
                "month": 4,
                "nanos": 0,
                "seconds": 0,
                "time": 1367769600000,
                "timezoneOffset": -480,
                "year": 113
            },
            "role": "普通用户"
        }
    ],
    "total": 13
}所有的id都为0,其他字段与数据库一样。。这个是怎么回事??看了半天没看出来。数据库hibernatejson