采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
mybatis里找不到老师分页器导的这个类,显示没有,然后就有一直报错!!!
There is no getter for property named 'delegate' in 'class com.sun.proxy.$Proxy32'
我觉得分页拦截器这这东西其实真没必要自己写,其实有一些不错的轮子蛮好用的,比如:
Mybatis PageHelper 地址:https://pagehelper.github.io/
Mybatis Plus 地址:http://mp.baomidou.com/
完全开箱即用,自己写真的很浪费时间。
嗯,从已经看见的代码和异常看不出来什么问题,你这个MetaObject对象确实有问题,导致metaObject.getValue("delegate.mappedStatement")执行不起来,我提供一下视频里这个类的代码,你放到你工程里替换你这个拦截器,看看能不能执行:
package org.imooc.dao.interceptor;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.imooc.bean.BaseBean;
import org.imooc.bean.Page;
@Intercepts({@Signature(type=StatementHandler.class,method="prepare",args={Connection.class})})
public class PageInterceptor implements Interceptor{
public Object intercept(Invocation arg0) throws Throwable {
StatementHandler statementHandler = (StatementHandler)arg0.getTarget();
MetaObject metaObject = MetaObject.forObject(statementHandler, SystemMetaObject.DEFAULT_OBJECT_FACTORY, SystemMetaObject.DEFAULT_OBJECT_WRAPPER_FACTORY,new DefaultReflectorFactory());
MappedStatement mappedStatement = (MappedStatement)metaObject.getValue("delegate.mappedStatement");
String id = mappedStatement.getId();
if(id.endsWith("ByPage")) {
BoundSql boundSql = statementHandler.getBoundSql();
String sql = boundSql.getSql();
String countSql = "select count(*) from(" + sql + ")t";
Connection conn = (Connection)arg0.getArgs()[0];
PreparedStatement statement = conn.prepareStatement(countSql);
ParameterHandler parameterHandler = (ParameterHandler)metaObject.getValue("delegate.parameterHandler");
parameterHandler.setParameters(statement);
ResultSet rs = statement.executeQuery();
BaseBean bean = (BaseBean)boundSql.getParameterObject();
Page page = bean.getPage();
if(rs.next()) {
page.setTotalNumber(rs.getInt(1));
}
String pageSql = sql + " limit " + (page.getCurrentPage() - 1) * page.getPageNumber() + "," + page.getPageNumber();
metaObject.setValue("delegate.boundSql.sql", pageSql);
}
return arg0.proceed();
}
public Object plugin(Object arg0) {
return Plugin.wrap(arg0, this);
}
public void setProperties(Properties arg0) {
}
}
那可能是部署有问题,下次再出现这种情况,把工程clean一下,然后重新添加到tomcat下
老师抽空帮我看看吧 ,真的无能为力了,照说逻辑上也不难,找原因找的源码我都快背出来了,delegate我打断点跟踪,最后是得到个method=null然后抛出了这个异常
老师版本改对之后,这个错误又不明白了 There is no getter for property named 'delegate' in 'class com.sun.proxy.$Proxy32'
老师,您的自动回复机器人我也看了几遍了,那个的mybatis版本是3.2.7的 里面的MetaObject.forObject()方法里有三个参数,在这套课程里,版本是3.3.0,参数变成了四个,但是不管我使用哪个版本,哪种写法都会报这个错误,这个问题已经困扰我几天了,我的jdk是1.7的,会不会问题出在这
登录后可查看更多问答,登录/注册
【毕设】SSM全面梳理,前后端分离,zTree 和复杂SQL打造权限系统,解惑MyBatis和RESTful
了解课程