1. 程式人生 > >java之註解

java之註解

序列化 property 數據庫 實體類 man 請求參數 數據 雙向 api

項目中常用註解整理: @JsonView註解
springBoot中使用jackjson定義多個視圖 https://blog.csdn.net/c_intmian/article/details/79543225 @Getter
@Setter
加入實體類名上 等價於get和set方法 @NoArgsConstructor
生成一個無參數的構造方法 @AllArgsContructor
生成一個包含所有變量的構造方法 @Entity
對實體類進行註釋 @Table
聲明此對象映射到數據庫的數據表 @Column
註解來標識實體類中屬性與數據表中字段的對應關系 @ApiModel:
描述一個Model的信息(這種一般用在post創建的時候,使用@RequestBody這樣的場景,請求參數無法使用@ApiImplicitParam註解進行描述的時候)
@ApiModelProperty:
描述一個model的屬性 @Where(clause = “condition = 1” )
加了這個註解就表示在執行hibernate查詢操作時 會自動在sql的where後加一個條件condition = 1;
例: 原:select * from user where id=‘5‘
加入後:select * from user where id=‘5‘ and condition=1
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
根據底層數據庫自動選擇方式,需要底層數據庫的設置 @Enumerated(EnumType.STRING)
采用枚舉類型與數據庫進行交互
枚舉類型介紹:https://blog.csdn.net/u014527058/article/details/52751488 @JsonProperty
此註解用於屬性上,作用是把該屬性的名稱序列化為另外一個名稱,如把trueName屬性序列化為name,@JsonProperty("name") @Transient
在實體集中聲明一個屬性,並設置它的setter和getter方法,並在字段上面加上這個註解 @Transient
private String cptName; @component
(把普通pojo實例化到spring容器中,相當於配置文件中的
<bean id="" class=""/>) @ManyToOne
單向多對一 @OneToOne
基於外鍵的雙向一對一

java之註解