| | |
| | | import org.apache.ibatis.plugin.*; |
| | | |
| | | import java.lang.reflect.Method; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Intercepts( |
| | | { |
| | |
| | | Object entity = invocation.getArgs()[PARAMETER_INDEX]; |
| | | if (entity instanceof BaseEntity) { |
| | | Class<?> entityClass = entity.getClass(); |
| | | Method setIdMt = null ; |
| | | Method setIdMt = null ; |
| | | try{ |
| | | setIdMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; |
| | | }catch (Exception e){ |
| | |
| | | } |
| | | |
| | | invocation.getArgs()[PARAMETER_INDEX] = entity; |
| | | }else if(entity instanceof Map){ |
| | | try { |
| | | ((List)((Map<?, ?>) entity).get("list")).forEach(e -> { |
| | | if (e instanceof BaseEntity) { |
| | | Class<?> entityClass = e.getClass(); |
| | | Method setIdMt = null ; |
| | | try{ |
| | | setIdMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; |
| | | if(setIdMt != null){ |
| | | setIdMt.invoke(e, new IDLongGenerator().generate()); |
| | | } |
| | | }catch (Exception e1){ |
| | | //当entityClass没有setId方法时,会抛出异常 |
| | | } |
| | | } |
| | | }); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | return invocation.proceed(); |