3.0.5版本
通过springboottest测试serivceImpl的方法:public boolean saveBatch(Collection entityList, int batchSize)
1、定义业务的UserServiceImpl
public class UserServiceImpl extends BaseServiceImpl implements UserService {
}
2、BaseServiceImpl的实现方式
public class BaseServiceImpl extends ServiceImpl, T> implements BaseService{
2、测试
@Test
public void saveBatchTest() {
List listUser = new ArrayList();
UserDO u1 = new UserDO();
u1.setName("l5");
u1.setAge(13);
u1.setCreateTime(LocalDateTime.now());
u1.setEnable(1);
u1.setPassword("123456");
listUser.add(u1);
UserDO u2 = new UserDO();
u2.setName("l6");
u2.setAge(14);
u2.setCreateTime(LocalDateTime.now());
u2.setEnable(0);
u2.setPassword("654321");
listUser.add(u2);
boolean result = userService.saveBatch(listUser, 2);
System.out.println("saveBatchTest result:" + result);
Assert.assertEquals(true, result);
}
报错信息:
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Cannot execute table Method, ClassGenricType not found .
at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:51)
at com.baomidou.mybatisplus.core.toolkit.Assert.isTrue(Assert.java:41)
at com.baomidou.mybatisplus.core.toolkit.Assert.notNull(Assert.java:75)
at com.baomidou.mybatisplus.core.toolkit.sql.SqlHelper.table(SqlHelper.java:94)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.sqlStatement(ServiceImpl.java:102)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveBatch(ServiceImpl.java:122)
at com.baomidou.mybatisplus.extension.service.IService.saveBatch(IService.java:53)
at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
at com.lls.samples.service.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$13e30d70.saveBatch()
at com.lls.samples.service.BizServiceAPPTest.saveBatchTest(BizServiceAPPTest.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
不知道是不是多重继承的问题
Comment From: miemieYaho
那就自行解决
Comment From: daize1994
怎么解决的?我也遇到了这个报错,但是没有多重继承
Comment From: jackwei
/*
*
* 获取TableInfo
*
*
* @param clazz 对象类
* @return TableInfo 对象表信息
/
public static TableInfo table(Class<?> clazz) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
if (null == tableInfo) {
throw new MybatisPlusException("Error: Cannot execute table Method, ClassGenricType not found .");
}
return tableInfo;
}
好吧,我也遇到这个问题了,看来还是没人解决啊
Comment From: ldbmcs
使用saveBatch,且没有多重继承,同样遇到了此问题,暂时无法解决
Comment From: liu-xinhui
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Cannot execute table Method, ClassGenricType not found
如果是多重继承导致的此错误,可以在覆写ServiceImpl中的currentModelClass方法
spring方式
/**
* 覆写mybatis-plus获取泛型class方式,防止多重继承时无法获取class
*/
@SuppressWarnings("all")
@Override
protected Class<T> currentModelClass() {
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), BaseService.class);
}
或者java方式
@SuppressWarnings("all")
@Override
protected Class<T> currentModelClass() {
ParameterizedType genType = (ParameterizedType) getClass().getGenericSuperclass();
Type type = genType.getActualTypeArguments()[0];
return (Class<T>) type;
}
Comment From: rawthfal
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: Cannot execute table Method, ClassGenricType not found
如果是多重继承导致的此错误,可以在覆写ServiceImpl中的currentModelClass方法
spring方式
/**
* 覆写mybatis-plus获取泛型class方式,防止多重继承时无法获取class
*/
@SuppressWarnings("all")
@Override
protected Class<T> currentModelClass() {
return (Class<T>) GenericTypeResolver.resolveTypeArgument(getClass(), BaseService.class);
}
```
或者java方式
@SuppressWarnings("all")
@Override
protected Class currentModelClass() {
ParameterizedType genType = (ParameterizedType) getClass().getGenericSuperclass();
Type type = genType.getActualTypeArguments()[0];
return (Class) type;
}
可以的