|  |  |  | 
|---|
|  |  |  | if (entity instanceof BaseEntity) { | 
|---|
|  |  |  | //Class<? extends Object> entityClass = entity.getClass(); | 
|---|
|  |  |  | Class<?> entityClass = entity.getClass(); | 
|---|
|  |  |  | Method setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; | 
|---|
|  |  |  | setMt.invoke(entity, new IDLongGenerator().generate()); | 
|---|
|  |  |  | Method setMt = null ; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | //有一些实体没有id,例如中间表 | 
|---|
|  |  |  | setMt = entityClass.getMethod(BASE_FIELD_SET_PRIMARY_KEY_FUNTION_NAME, Long.class) ; | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | //当entityClass没有setId方法时,会抛出异常 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(setMt != null){ | 
|---|
|  |  |  | setMt.invoke(entity, new IDLongGenerator().generate()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | invocation.getArgs()[PARAMETER_INDEX] = entity; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|