java.lang.ClassCastException: com.lt.po.Book
at com.lt.dao.impl.BookDao.findBookCount(BookDao.java:27)
at com.lt.service.impl.BookService.findBookCount(BookService.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy21.findBookCount(Unknown Source)
        ……
(报错信息)public Integer findBookCount(Integer bookId) {
return (Integer)getSqlMapClientTemplate().queryForObject("Book.findBookCount", bookId);
}public Integer findBookCount(Integer bookId){
bookCount=bookDao.findBookCount(bookId);
return bookCount;
}
/**
 * 保存一个借还记录
 * 对应的Action
 * @return
 * @throws Exception 
 */
public String saveLoanLog() throws Exception {
// Book book = (Book) getSession().getAttribute("book");
Book book = new Book();
book.setBookId(loanLog.getBookId());
bookId=book.getBookId();
loanLog.setLoanTime(new Date());
//loanLog.setBookId(book.getBookId());
bookCount=bookService.findBookCount(bookId);
bookLoanCount=bookService.findBookLoanCount(bookId);

//改变book的状态
if((bookCount-bookLoanCount)==0)
{
book.setState(2);
bookService.updateBook(book);
}
else if((bookCount-bookLoanCount)==bookCount)
{
book.setState(0);
bookService.updateBook(book);
}
else
{
book.setState(1);
bookService.updateBook(book);
}

loanId = (Integer) loanLogService.saveLoanLog(loanLog);
if (loanId != null) {
success = true;
}
return SUCCESS;
}

解决方案 »

  1.   

    具体是哪个类,不是要得到Integer类型的嘛
      

  2.   

    返回的类型要和你在xml文件里配置的一样
      

  3.   

    是不是public Integer findBookCount(Integer bookId) { 
    return (Integer)getSqlMapClientTemplate().queryForObject("Book.findBookCount", bookId); 

    这里是Integer,那对应的ibatis中xml也是integer
      

  4.   

    解决了..是xml那里的缘故
    谢谢