From 49fe5878720dc45775e7d46c14766eb3dcbc594c Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 19:14:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?doc:=20=E4=BF=AE=E5=A4=8D=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/faq.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/zh/faq.md b/docs/zh/faq.md index 72feb99b..69f50162 100644 --- a/docs/zh/faq.md +++ b/docs/zh/faq.md @@ -20,11 +20,12 @@ - 2、是否主动添加了 `mybatis-spring-boot-starter` 的依赖,导致版本不匹配。使用 SpringBoot 的情况下,应该引用 `mybatis-flex-spring-boot-starter` 就可以了,不需要再添加其他 MyBatis 依赖。 - 3、是否与 `mybatis-plus-boot-starter` 共用,使 MyBatis 被优先初始化,而导致 MyBatis-Flex 没有被加载。 -- 4、是否添加了 `pagehelper-spring-boot-starter` 依赖,导致传递了 `mybatis-plus-boot-starter` 依赖。如还想继续使用 pagehelper 插件,点击 [这里](#与-pagehelper-集成出现错误) 查看解决方案。 +- 4、是否添加了 `pagehelper-spring-boot-starter` 依赖,导致传递了 `mybatis-spring-boot-starter` 依赖。如还想继续使用 pagehelper 插件,点击 [这里](#与-pagehelper-集成出现错误) 查看解决方案。 ## 示例中的 AccountMapper 和 "ACCOUNT" 在哪里,报错了。 -MyBatis-Flex 使用了 APT 技术,这两个类是自动生成的。 +MyBatis-Flex 使用了 APT 技术,这两个类是自动生成的,如果已经生成但是导入不了,点击 [这里](./others/apt.md#开发工具无法导入生成的代码) 查看解决方案。 + 参考:[MyBatis-Flex APT 配置 - MyBatis-Flex 官方网站](./others/apt.md) ## 阿里镜像找不到依赖? From eaa7107b30d6e88dac65fc94cfa1ff274369cfca Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 19:14:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?doc:=20=E6=96=B0=E5=A2=9E=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BB=8B=E7=BB=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/base/active-record.md | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/zh/base/active-record.md b/docs/zh/base/active-record.md index f50178bf..a213ff21 100644 --- a/docs/zh/base/active-record.md +++ b/docs/zh/base/active-record.md @@ -1,6 +1,6 @@ # Active Record -[Active Record 模式](http://www.martinfowler.com/eaaCatalog/activeRecord.html)出自 Martin Fowler +[Active Record](http://www.martinfowler.com/eaaCatalog/activeRecord.html) 模式出自 Martin Fowler 写的《[企业应用架构模式](https://book.douban.com/subject/4826290/)》书中。在 Active Record 模式中,对象中既有持久存储的数据,也有针对数据的操作。Active Record 模式把数据存取逻辑作为对象的一部分,处理对象的用户知道如何把数据写入数据库,还知道如何从数据库中读出数据。 @@ -34,6 +34,7 @@ public class Account extends Model { private String userName; private Integer age; private Date birthday; + } ``` @@ -48,6 +49,7 @@ public class AccountController { public boolean save(@RequestBody Account account) { return account.save(); } + } ``` @@ -127,6 +129,17 @@ Account.create() .list(); ``` +### 查询单列数据 + +`Model` 提供了 `obj` 方法来查询单列数据: + +```java +Account.create() + .select(Account::getUserName) // 只查询 user_name 列数据 + .where(Account::getAge).ge(18) + .objList(); +``` + ### 查询分页数据 `Model` 提供了 `page` 方法来查询分页数据: @@ -162,7 +175,7 @@ User.create() .withRelations() // 使用 Relations Query 的方式进行关联查询。 .maxDepth(3) // 设置父子关系查询中,默认的递归查询深度。 .ignoreRelations("orderList") // 忽略查询部分 Relations 注解标记的属性。 - .extraCondition("id",100) // 添加额外的 Relations 查询条件。 + .extraConditionParam("id", 100) // 添加额外的 Relations 查询条件。 .one(); ``` @@ -174,16 +187,16 @@ User.create() User.create() .where(USER.USER_ID.eq(1)) .withFields() // 使用 Fields Query 的方式进行关联查询。 - .fieldMapping(User::getRoleList,user-> // 设置属性对应的 QueryWrapper 查询。 - QueryWrapper.create() - .select() - .from(ROLE) - .where(ROLE.ROLE_ID.in( - QueryWrapper.create() - .select(USER_ROLE.ROLE_ID) - .from(USER_ROLE) - .where(USER_ROLE.USER_ID.eq(user.getUserId())) - ))) + .fieldMapping(User::getRoleList, user -> // 设置属性对应的 QueryWrapper 查询。 + QueryWrapper.create() + .select() + .from(ROLE) + .where(ROLE.ROLE_ID.in( + QueryWrapper.create() + .select(USER_ROLE.ROLE_ID) + .from(USER_ROLE) + .where(USER_ROLE.USER_ID.eq(user.getUserId())) + ))) .one(); ``` From 946df440452c3707071acfa0a1ca1d3a4a84b084 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 2 Aug 2023 19:22:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E9=98=B2=E6=AD=A2=E5=88=87=E9=9D=A2?= =?UTF-8?q?=E8=A6=86=E7=9B=96=EF=BC=8C=E4=BF=AE=E5=A4=8D=20https://gitee.c?= =?UTF-8?q?om/mybatis-flex/mybatis-flex/issues/I7Q253?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/boot/MultiDataSourceAutoConfiguration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java index f111cca4..bc14eb06 100644 --- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java +++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java @@ -22,7 +22,6 @@ import com.mybatisflex.core.datasource.FlexDataSource; import com.mybatisflex.spring.datasource.DataSourceAdvice; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; -import org.springframework.aop.Advisor; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -95,7 +94,7 @@ public class MultiDataSourceAutoConfiguration { @Bean @ConditionalOnMissingBean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) - public Advisor dataSourceAdvice() { + public DataSourceAdvice dataSourceAdvice() { return new DataSourceAdvice(); }