diff --git a/pom.xml b/pom.xml
index 496c7ca..74aa791 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,12 +83,6 @@
${logback.version}
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatis-plus.version}
-
-
org.apache.tomcat.embed
@@ -128,7 +122,11 @@
pagehelper-spring-boot-starter
${pagehelper.boot.version}
-
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybatis-plus.version}
+
com.github.oshi
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
index 32eb6f1..5301569 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java
@@ -1,5 +1,6 @@
package com.ruoyi;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
* @author ruoyi
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
+@MapperScan("com.ruoyi.base.mapper")
public class RuoYiApplication
{
public static void main(String[] args)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java
index 3ddd611..4cdfcc2 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/base/controller/BaseConfigController.java
@@ -4,16 +4,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -40,11 +36,12 @@ public class BaseConfigController extends BaseController
* 查询基础配置-账户配置、小程序配置的内容列表
*/
@GetMapping("/list")
- public AjaxResult list(BaseConfig baseConfig)
+ public AjaxResult list(BaseConfig baseConfig,
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize)
{
-
- List list = baseConfigService.list();
- return success(list);
+ Page page = new Page<>(pageNo, pageSize);
+ return success(baseConfigService.queryListPage(baseConfig,page));
}
/**
@@ -98,6 +95,6 @@ public class BaseConfigController extends BaseController
public AjaxResult remove(@PathVariable String[] ids)
{
List list = new ArrayList<>(Arrays.asList(ids));
- return toAjax(baseConfigService.removeBatchByIds(list));
+ return toAjax(baseConfigService.removeByIds(list));
}
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseConfigMapper.java b/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseConfigMapper.java
index f50aa7f..dc9a609 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseConfigMapper.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/base/mapper/BaseConfigMapper.java
@@ -1,9 +1,13 @@
package com.ruoyi.base.mapper;
import java.util.List;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.base.domain.BaseConfig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
/**
* 基础配置-账户配置、小程序配置的内容Mapper接口
@@ -14,5 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BaseConfigMapper extends BaseMapper
{
-
+ IPage queryListPage(@Param("entity") BaseConfig entity, Page page);
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseConfigService.java b/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseConfigService.java
index 9c0b2c7..fbbcfd6 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseConfigService.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/base/service/IBaseConfigService.java
@@ -1,6 +1,9 @@
package com.ruoyi.base.service;
import java.util.List;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.base.domain.BaseConfig;
@@ -12,5 +15,5 @@ import com.ruoyi.base.domain.BaseConfig;
*/
public interface IBaseConfigService extends IService
{
-
+ IPage queryListPage(BaseConfig pageReqVO, Page page);
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseConfigServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseConfigServiceImpl.java
index f0cfc6b..e7e626c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseConfigServiceImpl.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/base/service/impl/BaseConfigServiceImpl.java
@@ -1,6 +1,9 @@
package com.ruoyi.base.service.impl;
import java.util.List;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -21,5 +24,8 @@ public class BaseConfigServiceImpl extends ServiceImpl queryListPage(BaseConfig pageReqVO, Page page) {
+ return baseConfigMapper.queryListPage(pageReqVO, page);
+ }
}
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index c7c2d52..5208fa8 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -98,13 +98,13 @@ token:
expireTime: 30
# MyBatis配置
-mybatis:
- # 搜索指定包别名
- typeAliasesPackage: com.ruoyi.**.domain
- # 配置mapper的扫描,找到所有的mapper.xml映射文件
- mapperLocations: classpath*:mapper/**/*Mapper.xml
- # 加载全局的配置文件
- configLocation: classpath:mybatis/mybatis-config.xml
+#mybatis:
+# # 搜索指定包别名
+# typeAliasesPackage: com.ruoyi.**.domain
+# # 配置mapper的扫描,找到所有的mapper.xml映射文件
+# mapperLocations: classpath*:mapper/**/*Mapper.xml
+# # 加载全局的配置文件
+# configLocation: classpath:mybatis/mybatis-config.xml
# MyBatis Plus 的配置项
mybatis-plus:
configuration:
@@ -120,9 +120,11 @@ mybatis-plus:
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
banner: false # 关闭控制台的 Banner 打印
mapper-locations:
+ - classpath*:mapper/**/*Mapper.xml
- classpath*:mapper/*/*.xml # 扫描子模块下的 mapper.xml文件
- classpath:mapper/*/*.xml # 扫描当前模块下的 mapper.xml 文件
- classpath*:mapper/*.xml
+ type-aliases-package: com.ruoyi.**.domain
# PageHelper分页插件
pagehelper:
helperDialect: mysql
diff --git a/ruoyi-admin/src/main/resources/mapper/base/BaseConfigMapper.xml b/ruoyi-admin/src/main/resources/mapper/base/BaseConfigMapper.xml
index 2ebbb49..cd75d0e 100644
--- a/ruoyi-admin/src/main/resources/mapper/base/BaseConfigMapper.xml
+++ b/ruoyi-admin/src/main/resources/mapper/base/BaseConfigMapper.xml
@@ -18,6 +18,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, code, json_str, creator, create_time, updater, update_time, del_flag from dl_base_config
+
\ No newline at end of file
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index bb76938..e985d7a 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -39,8 +39,26 @@
com.github.pagehelper
pagehelper-spring-boot-starter
+
+
+ mybatis-spring
+ org.mybatis
+
+
+ mybatis
+ org.mybatis
+
+
+ jsqlparser
+ com.github.jsqlparser
+
+
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
-
org.springframework.boot
@@ -118,11 +136,6 @@
javax.servlet
javax.servlet-api
-
-
- com.baomidou
- mybatis-plus-boot-starter
-
org.projectlombok
lombok
@@ -131,6 +144,28 @@
cn.hutool
hutool-all
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.3.0
+
+
+ com.baomidou
+ mybatis-plus-extension
+ 3.3.0
+
+
+ com.baomidou
+ mybatis-plus-core
+ 3.3.0
+
+
+ com.baomidou
+ mybatis-plus
+ 3.3.0
+
+
\ No newline at end of file
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java
index 03506e2..44b201f 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/DlBaseEntity.java
@@ -1,10 +1,13 @@
package com.ruoyi.common.core.domain;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
+import org.apache.ibatis.type.JdbcType;
import java.io.Serializable;
import java.util.Date;
@@ -23,17 +26,21 @@ public class DlBaseEntity implements Serializable
/** 创建者 */
+ @TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
private String creator;
/** 创建时间 */
+ @TableField(fill = FieldFill.INSERT)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 更新者 */
+ @TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
private String updater;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
/** 是否删除(0未删除|1已删除) */
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
index 057c941..74bc1c6 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MyBatisConfig.java
@@ -29,7 +29,7 @@ import com.ruoyi.common.utils.StringUtils;
*
* @author ruoyi
*/
-@Configuration
+//@Configuration
public class MyBatisConfig
{
@Autowired
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisAutoConfiguration.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisAutoConfiguration.java
new file mode 100644
index 0000000..b6a027a
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisAutoConfiguration.java
@@ -0,0 +1,36 @@
+package com.ruoyi.framework.config;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
+import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
+import com.baomidou.mybatisplus.extension.incrementer.KingbaseKeyGenerator;
+import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
+import com.baomidou.mybatisplus.extension.incrementer.PostgreKeyGenerator;
+import com.ruoyi.framework.handler.DefaultDBFieldHandler;
+import org.apache.ibatis.annotations.Mapper;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.ConfigurableEnvironment;
+
+/**
+ * MyBaits 配置类
+ *
+ * @author 芋道源码
+ */
+@Configuration() // 目的:先于 MyBatis Plus 自动配置,避免 @MapperScan 可能扫描不到 Mapper 打印 warn 日志
+@MapperScan(basePackages ={"com.ruoyi"}, annotationClass = Mapper.class,
+ lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试
+public class MybatisAutoConfiguration {
+
+
+ @Bean
+ public MetaObjectHandler defaultMetaObjectHandler(){
+ return new DefaultDBFieldHandler(); // 自动填充参数类
+ }
+
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/DefaultDBFieldHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/DefaultDBFieldHandler.java
new file mode 100644
index 0000000..70ef747
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/handler/DefaultDBFieldHandler.java
@@ -0,0 +1,70 @@
+package com.ruoyi.framework.handler;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.ruoyi.common.core.domain.DlBaseEntity;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.utils.SecurityUtils;
+import org.apache.ibatis.reflection.MetaObject;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * 通用参数填充实现类
+ *
+ * 如果没有显式的对通用参数进行赋值,这里会对通用参数进行填充、赋值
+ *
+ * @author hexiaowu
+ */
+public class DefaultDBFieldHandler implements MetaObjectHandler {
+
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof DlBaseEntity) {
+ DlBaseEntity baseDO = (DlBaseEntity) metaObject.getOriginalObject();
+
+ Date current =new Date();
+ // 创建时间为空,则以当前时间为插入时间
+ if (Objects.isNull(baseDO.getCreateTime())) {
+ baseDO.setCreateTime(current);
+ }
+ // 更新时间为空,则以当前时间为更新时间
+ if (Objects.isNull(baseDO.getUpdateTime())) {
+ baseDO.setUpdateTime(current);
+ }
+ // 获取当前的用户
+ Long userId = SecurityUtils.getUserId();
+ // 当前登录用户不为空,创建人为空,则当前登录用户为创建人
+ if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
+ baseDO.setCreator(userId.toString());
+ }
+ // 当前登录用户不为空,更新人为空,则当前登录用户为更新人
+ if (Objects.nonNull(userId) && Objects.isNull(baseDO.getUpdater())) {
+ baseDO.setUpdater(userId.toString());
+ }
+ }
+ }
+
+ @Override
+ public void updateFill(MetaObject metaObject) {
+ // 更新时间为空,则以当前时间为更新时间
+// Object modifyTime = getFieldValByName("updateTime", metaObject);
+// if (Objects.isNull(modifyTime)) {
+// setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
+// }
+//
+// // 当前登录用户不为空,更新人为空,则当前登录用户为更新人
+// Object modifier = getFieldValByName("updater", metaObject);
+// Long userId = WebFrameworkUtils.getLoginUserId();
+// if (Objects.nonNull(userId) && Objects.isNull(modifier)) {
+// setFieldValByName("updater", userId.toString(), metaObject);
+// }
+ //更新数据时,强制更新数据的更新时间和更新人
+ setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
+ Long userId = SecurityUtils.getUserId();
+ if (Objects.nonNull(userId)) {
+ setFieldValByName("updater", userId.toString(), metaObject);
+ }
+ }
+}