-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
支持mpp的多主键@MppMultiId可以和mp的单主键@TableId兼容
- Loading branch information
1 parent
4e637bd
commit 0f5f366
Showing
8 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/github/jeffreyning/mybatisplus/util/CheckId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.github.jeffreyning.mybatisplus.util; | ||
|
||
import com.baomidou.mybatisplus.core.metadata.TableInfo; | ||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
public class CheckId { | ||
//add 1.7.2 | ||
public static Field getIdField(Class<?> modelClass, String fieldName){ | ||
try { | ||
Field field=modelClass.getDeclaredField(fieldName); | ||
return field; | ||
} catch (NoSuchFieldException e) { | ||
Class superclass=modelClass.getSuperclass(); | ||
if(superclass!=null) { | ||
Field superField = getIdField(superclass, fieldName); | ||
return superField; | ||
}else{ | ||
return null; | ||
} | ||
} | ||
} | ||
//add 1.7.2 | ||
public static boolean appendIdColum(Class<?> modelClass, TableInfo tableInfo, Map idMap){ | ||
String keycol=tableInfo.getKeyColumn(); | ||
String keypro=tableInfo.getKeyProperty(); | ||
if(StringUtils.checkValNull(keypro)){ | ||
return false; | ||
} | ||
Field idField=getIdField(modelClass, keypro); | ||
if(idField!=null){ | ||
MppMultiId mppMultiId=idField.getAnnotation(MppMultiId.class); | ||
if(mppMultiId!=null){ | ||
String attrName=keypro; | ||
String colName=keycol; | ||
idMap.put(attrName, colName); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |