ssh框架,model里有Result和Count两个不同的类
public class Result {
private int day;
private int month;
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
}
public class Count {
private int id;
private String indate;
public String getIndate() {
return indate;
}
public void setIndate(String indate) {
this.indate = indate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Dao的实现类中有如下代码:
...
List<Result> list=(List<Result>)hibernateTemplate.find("select day(indate),month(indate) from com.chart.model.Count group by day(indate)");
System.out.println(list.get(0).getDay());<==========打印不出来
...
为什么打印不出来呢?
list里面有值,是不是因为不能转换成Result类型,改怎么改呢?

解决方案 »

  1.   

    你直接去数据库执行你的sql语句看看能不能查询出结果;
    还有既然用了hibernate何必还使用原生的sql呢,用hql或是Criteria吧
      

  2.   

    select day(indate),month(indate) from com.chart.model.Count group by day(indate)");
    你这hql怎么看起来挺奇怪啊,day(indate),这个是什么,你查的是Count表,怎么返回的是Result
    看不懂你的意思
      

  3.   

    回复于: 2013-05-15 11:31:19
    你直接去数据库执行你的sql语句看看能不能查询出结果;
    还有既然用了hibernate何必还使用原生的sql呢,用hql或是Criteria吧
      

  4.   

    lz,spring中这样查出来的是list里面放置的是map类型。你确定你这样写list.get(0).getDay()不报错?你这样写list.get(0).get("day")试试。
      

  5.   

    select day(indate),month(indate) from com.chart.model.Count group by day(indate)");
    你这hql怎么看起来挺奇怪啊,day(indate),这个是什么,你查的是Count表,怎么返回的是Result
    看不懂你的意思
    day(indate)是取日期中的“日”,我查的是Count,但是我想把结果转换成Result类型的,上面的代码转不过去,想知道怎么才能转过去呢~
      

  6.   

    "select day(indate),month(indate) from com.chart.model.Count group by day(indate)")
    用这个sql语句,怎么能确定生成的List<Result>,Result的day是被赋值了day(indate),month是被赋值了
    month(indate)??????????????