Forráskód Böngészése

添加mybatis-plus分页插件相关配置

limingming 1 éve
szülő
commit
26c4bbce67

+ 0 - 28
rouyi-api/src/main/java/com/info666/infraredRemote/controller/ccc.java

@@ -1,28 +0,0 @@
-package com.info666.infraredRemote.controller;
-
-import com.alibaba.fastjson2.JSONObject;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Author: LiMingMing
- * @Date: 2023/7/13 20:57
- * @Description: TODO
- **/
-public class ccc {
-    public static void main(String[] args) {
-        Map map = new HashMap();
-        map.put("x", 1);
-        map.put("y", 2);
-        map.put("h", 3);
-        map.put("w", 4);
-        JSONObject from = JSONObject.from(map);
-        System.out.println(from);
-        Map<String, Object> userMap = new HashMap<>();
-        for (Map.Entry<String, Object> stringObjectEntry : from.entrySet()) {
-            userMap.put(stringObjectEntry.getKey(),stringObjectEntry.getValue());
-        }
-        System.out.println(userMap.get("x"));
-    }
-}

+ 24 - 6
ruoyi-admin/src/main/resources/application.yml

@@ -99,14 +99,32 @@ token:
   # 令牌有效期(默认30分钟)
   expireTime: 30
 
-# MyBatis配置
-mybatis:
-  # 搜索指定包别名
+## MyBatis配置
+#mybatis:
+#  # 搜索指定包别名
+#  typeAliasesPackage: com.ruoyi.**.domain
+#  # 配置mapper的扫描,找到所有的mapper.xml映射文件
+#  mapperLocations: classpath*:mapper/**/*Mapper.xml
+#  # 加载全局的配置文件
+#  configLocation: classpath:mybatis/mybatis-config.xml
+
+
+# MyBatis-plus配置
+mybatis-plus:
+  # 指定实体类所在包的路径,MyBatis-Plus 会自动扫描该路径下的实体类
   typeAliasesPackage: com.ruoyi.**.domain
-  # 配置mapper的扫描,找到所有的mapper.xml映射文件
+  # 指定 Mapper 接口所在包的路径,MyBatis-Plus 会自动扫描该路径下的 Mapper 接口
   mapperLocations: classpath*:mapper/**/*Mapper.xml
-  # 加载全局的配置文件
-  configLocation: classpath:mybatis/mybatis-config.xml
+  # 指定 MyBatis 全局配置文件的位置
+  #  configLocation: classpath:mybatis/mybatis-config.xml
+  configuration:
+    #在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射
+    map-underscore-to-camel-case: true
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+  global-config:
+    db-config:
+      id-type: ASSIGN_ID
+
 
 # PageHelper分页插件
 pagehelper:

+ 20 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/config/MybatisPlusConfig.java

@@ -0,0 +1,20 @@
+package com.ruoyi.common.core.config;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class MybatisPlusConfig {
+    /**
+     * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
+     */
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+        return interceptor;
+    }
+}

+ 0 - 5
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/PageInfo.java

@@ -1,6 +1,5 @@
 package com.ruoyi.common.core.domain;
 
-import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -19,25 +18,21 @@ public class PageInfo<T> implements Serializable {
     /**
      * 总数
      */
-    @ApiModelProperty(value = "总数")
     private long total = 0;
 
     /**
      * 每页显示条数
      */
-    @ApiModelProperty(value = "每页显示条数")
     private long size = 10;
 
     /**
      * 当前页
      */
-    @ApiModelProperty(value = "当前页")
     private long current = 1;
 
     /**
      * 查询数据列表
      */
-    @ApiModelProperty(value = "数据列表")
     private List<T> records = Collections.emptyList();
     public PageInfo(List<T> records){
         this.records = records;

+ 16 - 24
ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java

@@ -1,15 +1,8 @@
 package com.ruoyi.framework.config;
 
-import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
-import com.ruoyi.common.utils.StringUtils;
-import org.apache.ibatis.io.VFS;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.env.Environment;
-import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 import org.springframework.core.io.support.ResourcePatternResolver;
@@ -18,7 +11,6 @@ import org.springframework.core.type.classreading.MetadataReader;
 import org.springframework.core.type.classreading.MetadataReaderFactory;
 import org.springframework.util.ClassUtils;
 
-import javax.sql.DataSource;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -114,20 +106,20 @@ public class MyBatisConfig
         return resources.toArray(new Resource[resources.size()]);
     }
 
-    @Bean
-    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
-    {
-        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
-        String mapperLocations = env.getProperty("mybatis.mapperLocations");
-        String configLocation = env.getProperty("mybatis.configLocation");
-        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
-        VFS.addImplClass(SpringBootVFS.class);
-
-        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
-        sessionFactory.setDataSource(dataSource);
-        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
-        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
-        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
-        return sessionFactory.getObject();
-    }
+//    @Bean
+//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
+//    {
+//        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
+//        String mapperLocations = env.getProperty("mybatis.mapperLocations");
+//        String configLocation = env.getProperty("mybatis.configLocation");
+//        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
+//        VFS.addImplClass(SpringBootVFS.class);
+//
+//        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
+//        sessionFactory.setDataSource(dataSource);
+//        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
+//        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
+//        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
+//        return sessionFactory.getObject();
+//    }
 }