From 30bcaac63cafe8ed46a7ab09eac6b90fa7aea1d5 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 08 十一月 2023 09:38:36 +0800
Subject: [PATCH] 代码整理,及应用MybatisPlus,使得可不用mapper.xml配置文件进行查询demo实现
---
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java | 25 ++++++++++---------------
1 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
index 1729ef2..e9db338 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mybatis/AutoGenerateIdInterceptor.java
@@ -27,29 +27,24 @@
static int MAPPED_STATEMENT_INDEX = 0;
static int PARAMETER_INDEX = 1;
- static int ROWBOUNDS_INDEX = 2;
- static int RESULT_HANDLER_INDEX = 3;
static String BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME = "setId";
- static String BASE_FIELD_SET_CREATE_TIME_FUNTION_NAME = "setCreateDt";
- static String BASE_FIELD_SET_UPDATE_TIME_FUNTION_NAME = "setUpdateDt";
- static String BASE_FIELD_SET_DELETE_FUNTION_NAME = "setDelete";
- public AutoGenerateIdInterceptor() {
- //System.out.println("auto generate primaryKey mybatis plugin start!!!");
- }
-
- @SuppressWarnings("static-access")
+ /**
+ * 鎷︽埅閫昏緫瀹炵幇
+ * @param invocation 浠g悊
+ * @return Object
+ * @throws Throwable 寮傚父
+ */
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX];
SqlCommandType commandType = mappedStatement.getSqlCommandType();
- if (commandType.INSERT.equals(SqlCommandType.INSERT)) {
+ if (commandType.equals(SqlCommandType.INSERT)) {
Object entity = invocation.getArgs()[PARAMETER_INDEX];
if (entity instanceof BaseEntity) {
- Class<? extends Object> entityClass = entity.getClass();
+ //Class<? extends Object> entityClass = entity.getClass();
+ Class<?> entityClass = entity.getClass();
Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ;
- if(setMt != null){
- setMt.invoke(entity, new IDLongGenerator().generate());
- }
+ setMt.invoke(entity, new IDLongGenerator().generate());
invocation.getArgs()[PARAMETER_INDEX] = entity;
}
}
--
Gitblit v1.8.0