java開發(fā)MyBatis中常用plus實體類注解符詳解
mybatis-plus常用注解符
1. 表名注解(@TableName)
作用:實體類和數(shù)據(jù)庫中表建立對應關系:如
@TableName("thotset")
public class HotsetEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Integer fclass;
private Integer fpwid;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date fbdate;
@JsonFormat(pattern = "yyyy-MM-dd")
private Date fedate;
}
代表:HotsetEntity 對應數(shù)據(jù)庫中表為thotset
2. 主鍵注解(@TableId)
作用:標識實體類的屬性對應的是表中的主鍵,還配置主鍵的生成策略,如:
@TableName("tsvbase")
public class PaintLifeEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private String recid;
private String fcode;
private String fname;
}
代表:recid是表中的主鍵,主鍵的生成策略為自增類型。
在mybaits-plus中主鍵生成策略及注意事項
IdType.ASSIGN_ID: 主鍵類型為長整型或字符串,使用這類主鍵時要注意,在前端長整形在數(shù)據(jù)轉(zhuǎn)換時和整型長度不匹配問題,會引發(fā)錯誤。
IdType.ASSIGN_UUID:主鍵類型為String,為32為不重復字符串。注意該字符串為亂序,使用它時注意一條記錄,頁面刷新后新增的記錄并非最后一條或第一條,經(jīng)常找不到新增的記錄,維護時用戶體驗很差。
IdType.AUTO:自增;
IdType.input: 插入數(shù)據(jù)前需要使用其他方式得到主鍵,將得到的數(shù)據(jù)賦值到主鍵上。
IdType.NONE:無狀態(tài),類同于Input
注 mybatis-plus其他主鍵注解在高版本已經(jīng)廢棄
3. 屬性注解(@TableField)
作用:該屬性非主鍵屬性,解決屬性名與字段名不匹配問題、屬性是否是數(shù)據(jù)表中字段、insert、update生成策略等。如:
@TableName("thotset")
public class HotsetEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Integer fclass;
private Integer fpwid;
@TableField(vlaue="fb_date")
private Date fbdate;
@TableField(exist=false)
private Date fedate;
}
第一個注解代表屬性fbDate對應的數(shù)據(jù)庫字段名為fb_date
第二個注解代表fedate屬性不與表中的字段匹配,在新增、修改時,不用去匹配
常用的就這三個,其他注解不再詳細描述。
以上就是java開發(fā)MyBatis常用plus實體類注解符詳解的詳細內(nèi)容,更多關于MyBatis常用plus實體類注解的資料請關注腳本之家其它相關文章!
相關文章
springboot使用定時器@Scheduled不管用的解決
這篇文章主要介紹了springboot使用定時器@Scheduled不管用的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
java 中 System.out.println()和System.out.write()的區(qū)別
這篇文章主要介紹了 java 中 System.out.println()和System.out.write()的區(qū)別.的相關資料,需要的朋友可以參考下2017-04-04

