Feat:动态代码编译引擎成熟!

This commit is contained in:
wangyu 2021-01-05 00:24:58 +08:00
parent 2f2ae4b6ef
commit 726d9fd4e5
5 changed files with 22 additions and 6 deletions

View File

@ -47,4 +47,10 @@ public class JavaSource {
public String getQueryBeanClassName() {
return StringUtils.substringAfterLast(queryBeanClass, ".");
}
// 获取限定查询实体的后缀
public String getQueryBeanSuffix() {
String beanClassName = getBeanClassName();
return queryBeanClass.contains(beanClassName) ? "" : "<" + beanClassName + ">";
}
}

View File

@ -1,8 +1,6 @@
package com.flyfish.framework.domain.base;
import com.flyfish.framework.builder.CriteriaBuilder;
import com.flyfish.framework.domain.base.BaseQo;
import com.flyfish.framework.domain.base.Domain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Sort;
@ -16,7 +14,7 @@ import java.util.Collection;
*/
@Getter
@Setter
public abstract class NameLikeQo<T extends Domain> extends BaseQo<T> {
public class NameLikeQo<T extends Domain> extends BaseQo<T> {
protected String name;

View File

@ -2,6 +2,7 @@ package com.flyfish.framework.beans.annotations;
import com.flyfish.framework.controller.BaseController;
import com.flyfish.framework.controller.SafeController;
import com.flyfish.framework.domain.base.NameLikeQo;
import com.flyfish.framework.domain.base.Qo;
import com.flyfish.framework.repository.DefaultRepository;
import com.flyfish.framework.service.BaseService;
@ -34,7 +35,7 @@ public @interface RestBean {
* 必须指定qo
* @return 结果
*/
Class<? extends Qo<?>> queryClass();
Class<? extends Qo> queryClass() default NameLikeQo.class;
/**
* 仓库的超类默认是default

View File

@ -86,7 +86,7 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
.setBeanClass(clazz.getCanonicalName())
.setQueryBeanClass(restBean.queryClass().getCanonicalName())
.setPackageName(basePackages.stream().findFirst().orElse("com.flyfish.project"))
.setUri(StringUtils.isBlank(restBean.value()) ? StringFormats.camel2Line(clazz.getSimpleName()) : restBean.value());
.setUri(makePath(clazz.getSimpleName(), restBean.value()));
// 分别生成实现类从repo到controller
templates.forEach((key, template) -> {
source.setSuperClass(superClasses.get(key).apply(restBean).getCanonicalName());
@ -134,6 +134,17 @@ public class RestBeanAutoConfigure implements ImportBeanDefinitionRegistrar, Res
}
}
/**
* 创建路径缺省加s对于错误拼写需要直接指定
*
* @param className 类名
* @param uri 路径
* @return 结果
*/
private String makePath(String className, String uri) {
return StringUtils.isBlank(uri) ? (StringFormats.camel2Line(className) + "s") : uri;
}
/**
* 获取基本扫描包路径
*

View File

@ -8,6 +8,6 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("#{uri}")
public class #{className} extends #{superClassName}<#{beanClassName}, #{queryBeanClassName}> {
public class #{className} extends #{superClassName}<#{beanClassName}, #{queryBeanClassName}#{queryBeanSuffix}> {
}