依赖调整为 com.baomidou:mybatis-plus-solon-plugin

This commit is contained in:
yulichang 2024-11-12 17:42:21 +08:00
parent 9dd1cfbde7
commit 42a63cf4d1
6 changed files with 9 additions and 358 deletions

View File

@ -9,7 +9,7 @@
```
#### Tips:
[solon 2.8.0 需要添加如下配置(此问题会在 MPJ 1.4.13+ 解决)](https://gitee.com/best_handsome/mybatis-plus-join/issues/I9RN5N)
如果出现 `Invalid bound statement (not found)` 添加如下配置
```yml
mybatis.db1:
globalConfig:
@ -24,27 +24,5 @@ import com.github.yulichang.base.MPJBaseMapper;
@Mapper
public interface UserMapper extends MPJBaseMapper<UserDO> {
}
```
### (可选)service继承MPJBaseService
```java
import com.github.yulichang.mybatisplusjoin.solon.plugin.base.MPJBaseService;
public interface UserService extends MPJBaseService<UserDO> {
}
```
### (可选)serviceImpl继承MPJBaseServiceImpl
```java
import com.github.yulichang.mybatisplusjoin.solon.plugin.base.MPJBaseServiceImpl;
import org.noear.solon.annotation.Component;
@Component
public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, UserDO> implements UserService {
}
```

View File

@ -42,9 +42,14 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>mybatis-plus-extension-solon-plugin</artifactId>
<scope>provided</scope>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-solon-plugin</artifactId>
<version>${mybatis.plus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-jsqlparser</artifactId>
<version>${mybatis.plus.version}</version>
</dependency>
</dependencies>

View File

@ -1,14 +0,0 @@
package com.github.yulichang.mybatisplusjoin.solon.plugin.base;
import com.baomidou.mybatisplus.solon.service.IService;
import com.github.yulichang.base.JoinService;
/**
* 基础service
* 目前包含两个模块 连表查询 关系映射
*
* @author yulichang
*/
public interface MPJBaseService<T> extends IService<T>, JoinService<T> {
}

View File

@ -1,13 +0,0 @@
package com.github.yulichang.mybatisplusjoin.solon.plugin.base;
import com.baomidou.mybatisplus.solon.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseMapper;
/**
* @author yulichang
* @see ServiceImpl
*/
@SuppressWarnings("unused")
public class MPJBaseServiceImpl<M extends MPJBaseMapper<T>, T> extends ServiceImpl<M, T> implements MPJBaseService<T> {
}

View File

@ -1,244 +0,0 @@
package com.github.yulichang.mybatisplusjoin.solon.plugin.base;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.solon.service.IService;
import com.github.yulichang.annotation.EntityMapping;
import com.github.yulichang.annotation.FieldMapping;
import com.github.yulichang.extension.mapping.config.DeepConfig;
import com.github.yulichang.extension.mapping.relation.Relation;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* 深度查询
* <p>
* 对配置了映射注解的字段进行查询
* 目前查询深度只支持2级(只解析当前实体类的映射注解,不会对查询结果再次解析注解)
* 多级查询可能存在循环引用的问题也可能会导致全量查询
*
* @author yulichang
* @see EntityMapping
* @see FieldMapping
* @since 1.2.0
*/
@SuppressWarnings({"unused"})
public interface MPJDeepService<T> extends IService<T> {
/**
* 根据 ID 查询 并关联全部映射
*
* @param id 主键ID
*/
default T getByIdDeep(Serializable id) {
return Relation.mpjGetRelation(getById(id), DeepConfig.defaultConfig());
}
/**
* 根据 ID 查询 并关联指定映射
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param id 主键ID
* @param config 映射配置
*/
default <R> T getByIdDeep(Serializable id, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(getById(id), config.apply(DeepConfig.builder()).build());
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectByIdDeep(1, Arrays.asList(User::getId, ... ))
*
* @param id 主键ID
* @param config 映射配置
*/
default <R> T getByIdDeep(Serializable id, DeepConfig<T> config) {
return Relation.mpjGetRelation(getById(id), config);
}
/**
* 查询根据ID 批量查询
*
* @param idList 主键ID列表(不能为 null 以及 empty)
*/
default List<T> listByIdsDeep(Collection<? extends Serializable> idList) {
return Relation.mpjGetRelation(listByIds(idList), DeepConfig.defaultConfig());
}
/**
* 查询根据ID 批量查询
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param idList 主键ID列表(不能为 null 以及 empty)
* @param config 映射配置
*/
default <R> List<T> listByIdsDeep(Collection<? extends Serializable> idList, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(listByIds(idList), config.apply(DeepConfig.builder()).build());
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectBatchIdsDeep(idList, Arrays.asList(User::getId, ... ))
*
* @param idList 主键ID列表(不能为 null 以及 empty)
* @param config 映射配置
*/
default <R> List<T> listByIdsDeep(Collection<? extends Serializable> idList, DeepConfig<T> config) {
return Relation.mpjGetRelation(listByIds(idList), config);
}
/**
* 查询根据 columnMap 条件
*
* @param columnMap 表字段 map 对象
*/
default List<T> listByMapDeep(Map<String, Object> columnMap) {
return Relation.mpjGetRelation(listByMap(columnMap), DeepConfig.defaultConfig());
}
/**
* 查询根据 columnMap 条件
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param columnMap 表字段 map 对象
* @param config 映射配置
*/
default <R> List<T> listByMapDeep(Map<String, Object> columnMap, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(listByMap(columnMap), config.apply(DeepConfig.builder()).build());
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectByMapDeep(columnMap, Arrays.asList(User::getId, ... ))
*
* @param columnMap 表字段 map 对象
* @param config 映射配置
*/
default <R> List<T> listByMapDeep(Map<String, Object> columnMap, DeepConfig<T> config) {
return Relation.mpjGetRelation(listByMap(columnMap), config);
}
/**
* 根据 entity 条件查询一条记录
*
* @param queryWrapper 实体对象封装操作类可以为 null
*/
default T getOneDeep(Wrapper<T> queryWrapper) {
return Relation.mpjGetRelation(getOne(queryWrapper), DeepConfig.defaultConfig());
}
/**
* 根据 entity 条件查询一条记录
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R> T getOneDeep(Wrapper<T> queryWrapper, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(getOne(queryWrapper), config.apply(DeepConfig.builder()).build());
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectOneDeep(queryWrapper, Arrays.asList(User::getId, ... ))
*
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R> T getOneDeep(Wrapper<T> queryWrapper, DeepConfig<T> config) {
return Relation.mpjGetRelation(getOne(queryWrapper), config);
}
/**
* 根据 entity 条件查询全部记录
*
* @param queryWrapper 实体对象封装操作类可以为 null
*/
default List<T> listDeep(Wrapper<T> queryWrapper) {
return Relation.mpjGetRelation(list(queryWrapper), DeepConfig.defaultConfig());
}
/**
* 根据 entity 条件查询全部记录
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R> List<T> listDeep(Wrapper<T> queryWrapper, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(list(queryWrapper), config.apply(DeepConfig.builder()).build());
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectListDeep(queryWrapper, Arrays.asList(User::getId, ... ))
*
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R> List<T> listDeep(Wrapper<T> queryWrapper, DeepConfig<T> config) {
return Relation.mpjGetRelation(list(queryWrapper), config);
}
/**
* 根据 entity 条件查询全部记录并翻页
*
* @param page 分页查询条件可以为 RowBounds.DEFAULT
* @param queryWrapper 实体对象封装操作类可以为 null
*/
default <E extends IPage<T>> E pageDeep(E page, Wrapper<T> queryWrapper) {
E e = page(page, queryWrapper);
Relation.mpjGetRelation(e.getRecords(), DeepConfig.defaultConfig());
return e;
}
/**
* 根据 entity 条件查询全部记录并翻页
* <p>
* JDK 默认不推荐泛型数组会引起 Java堆污染(Heap Pollution)
*
* @param page 分页查询条件可以为 RowBounds.DEFAULT
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R, E extends IPage<T>> E pageDeep(E page, Wrapper<T> queryWrapper, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
E e = page(page, queryWrapper);
Relation.mpjGetRelation(e.getRecords(), config.apply(DeepConfig.builder()).build());
return e;
}
/**
* 针对可变参数堆污染提供的重载
* list为null或空会查询全部映射关系
* <p>
* selectPageDeep(page, queryWrapper, Arrays.asList(User::getId, ... ))
*
* @param page 分页查询条件可以为 RowBounds.DEFAULT
* @param queryWrapper 实体对象封装操作类可以为 null
* @param config 映射配置
*/
default <R, E extends IPage<T>> E pageDeep(E page, Wrapper<T> queryWrapper, DeepConfig<T> config) {
E e = page(page, queryWrapper);
Relation.mpjGetRelation(e.getRecords(), config);
return e;
}
}

View File

@ -1,61 +0,0 @@
package com.github.yulichang.mybatisplusjoin.solon.plugin.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.solon.service.IService;
import com.github.yulichang.annotation.EntityMapping;
import com.github.yulichang.annotation.FieldMapping;
import com.github.yulichang.extension.mapping.config.DeepConfig;
import com.github.yulichang.extension.mapping.relation.Relation;
import java.util.function.Function;
/**
* 深度查询
* <p>
* 对配置了映射注解的字段进行查询
* 目前查询深度只支持2级(只解析当前实体类的映射注解,不会对查询结果再次解析注解)
* 多级查询可能存在循环引用的问题也可能会导致全量查询
* 用于替换deep
*
* @author yulichang
* @see EntityMapping
* @see FieldMapping
* @since 1.4.4
*/
@SuppressWarnings({"unchecked", "unused"})
public interface MPJRelationService<T> extends IService<T> {
/**
* 通过注解实现单表多次查询
*
* @param function BaseMapper调用方法
* @see EntityMapping
* @see FieldMapping
*/
default <R, M extends BaseMapper<T>> R getRelation(Function<M, R> function) {
return Relation.mpjGetRelation(function.apply((M) getBaseMapper()), DeepConfig.defaultConfig());
}
/**
* 通过注解实现单表多次查询
*
* @param function BaseMapper调用方法
* @see EntityMapping
* @see FieldMapping
*/
default <R, M extends BaseMapper<T>> R getRelation(Function<M, R> function, DeepConfig<T> config) {
return Relation.mpjGetRelation(function.apply((M) getBaseMapper()), config);
}
/**
* 通过注解实现单表多次查询
*
* @param function BaseMapper调用方法
* @param config 映射配置
* @see EntityMapping
* @see FieldMapping
*/
default <R, M extends BaseMapper<T>> R getRelation(Function<M, R> function, Function<DeepConfig.Builder<T>, DeepConfig.Builder<T>> config) {
return Relation.mpjGetRelation(function.apply((M) getBaseMapper()), config.apply(DeepConfig.builder()).build());
}
}