miemie 2020-11-07 20:15:06 +08:00
parent d2dccecc7b
commit a7833d270d
6 changed files with 100 additions and 6 deletions

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2011-2020, baomidou (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.core;
import org.apache.ibatis.builder.annotation.MethodResolver;
/**
* 继承 {@link MethodResolver}
*
* @author miemie
* @since 2019-01-05
*/
public class InjectorResolver extends MethodResolver {
private final MybatisMapperAnnotationBuilder annotationBuilder;
public InjectorResolver(MybatisMapperAnnotationBuilder annotationBuilder) {
super(annotationBuilder, null);
this.annotationBuilder = annotationBuilder;
}
@Override
public void resolve() {
annotationBuilder.parserInjector();
}
}

View File

@ -117,13 +117,22 @@ public class MybatisMapperAnnotationBuilder extends MapperAnnotationBuilder {
}
}
// TODO 注入 CURD 动态 SQL , 放在在最后, because 可能会有人会用注解重写sql
if (GlobalConfigUtils.isSupperMapperChildren(configuration, type)) {
GlobalConfigUtils.getSqlInjector(configuration).inspectInject(assistant, type);
try {
// https://github.com/baomidou/mybatis-plus/issues/3038
if (GlobalConfigUtils.isSupperMapperChildren(configuration, type)) {
parserInjector();
}
} catch (IncompleteElementException e) {
configuration.addIncompleteMethod(new InjectorResolver(this));
}
}
parsePendingMethods();
}
void parserInjector() {
GlobalConfigUtils.getSqlInjector(configuration).inspectInject(assistant, type);
}
private boolean canHaveStatement(Method method) {
// issue #237
return !method.isBridge() && !method.isDefault();

View File

@ -15,7 +15,6 @@
*/
package com.baomidou.mybatisplus.core;
import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
import org.apache.ibatis.builder.annotation.MethodResolver;
import java.lang.reflect.Method;
@ -31,9 +30,9 @@ public class MybatisMethodResolver extends MethodResolver {
private final MybatisMapperAnnotationBuilder annotationBuilder;
private final Method method;
public MybatisMethodResolver(MapperAnnotationBuilder annotationBuilder, Method method) {
public MybatisMethodResolver(MybatisMapperAnnotationBuilder annotationBuilder, Method method) {
super(annotationBuilder, method);
this.annotationBuilder = (MybatisMapperAnnotationBuilder) annotationBuilder;
this.annotationBuilder = annotationBuilder;
this.method = method;
}

View File

@ -45,6 +45,7 @@ import static java.util.stream.Collectors.joining;
* @author hubin
* @since 2018-04-06
*/
@SuppressWarnings("serial")
public abstract class AbstractMethod implements Constants {
protected static final Log logger = LogFactory.getLog(AbstractMethod.class);

View File

@ -34,7 +34,7 @@ import org.apache.ibatis.mapping.SqlSource;
* @author hubin
* @since 2018-04-06
*/
@SuppressWarnings("all")
@SuppressWarnings("serial")
public class Insert extends AbstractMethod {
@Override

View File

@ -0,0 +1,46 @@
package com.baomidou.mybatisplus.core;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.CacheNamespaceRef;
import org.junit.jupiter.api.Test;
/**
* @author miemie
* @since 2020-11-07
*/
class MybatisMapperAnnotationBuilderTest {
@Test
void parse() {
MybatisConfiguration configuration = new MybatisConfiguration();
MybatisMapperAnnotationBuilder a = new MybatisMapperAnnotationBuilder(configuration, AMapper.class);
a.parse();
MybatisMapperAnnotationBuilder b = new MybatisMapperAnnotationBuilder(configuration, BMapper.class);
b.parse();
configuration.getMappedStatement(AMapper.class.getName() + ".insert");
}
@CacheNamespaceRef(BMapper.class)
interface AMapper extends BaseMapper<A> {
}
@CacheNamespace
interface BMapper extends BaseMapper<B> {
}
@Data
private static class A {
private Long id;
}
@Data
@EqualsAndHashCode(callSuper = true)
private static class B extends A {
}
}